/******************************************************************/
/* ACM ICPC 2017-2018, NEERC                                      */
/* Northern Subregional Contest                                   */
/* St Petersburg, November 4, 2017                                */
/******************************************************************/
/* Problem L. Little Difference                                   */
/*                                                                */
/* Original idea         Dmitry Yakutov                           */
/* Problem statement     Pavel Kunyavskiy                         */
/* Test set              Pavel Kunyavskiy                         */
/******************************************************************/
/* Checker                                                        */
/*                                                                */
/* Author                Pavel Kunyavskiy                         */
/******************************************************************/

import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;

import java.util.Arrays;

import static ru.ifmo.testlib.Outcome.Type.OK;
import static ru.ifmo.testlib.Outcome.Type.WA;

public class Check implements Checker {
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        long n = inf.nextLong();
        int pa = ouf.nextInt();
        int ja = ans.nextInt();
        if (pa != ja) {
            return new Outcome(WA, "Wrong number of answers expected " + ja + " found " + pa);
        }
        if (pa == -1) {
            return new Outcome(OK, "Infinite number of decompositions");
        }
        long[][] answers = new long[pa][];
        for (int i = 0; i < pa; i++) {
            int k = ouf.nextInt();
            if (k > 100 || k <= 0) {
                return new Outcome(WA, "Strange number of integers " + k + "in decomposition #" + (i + 1));
            }
            answers[i] = new long[k];
            long prod = 1;
            for (int j = 0; j < k; j++) {
                answers[i][j] = ouf.nextLong();
                if (answers[i][j] <= 0) {
                    return new Outcome(WA, "Strange integer " + answers[i][j] + "in decomposition #" + (i + 1) + "on position " + (j + 1));
                }
                if (answers[i][j] > n / prod) {
                    return new Outcome(WA, "Wrong product decomposition #" + (i + 1));
                }
                prod *= answers[i][j];
            }
            if (prod != n) {
                return new Outcome(WA, "Wrong product decomposition #" + (i + 1));
            }
            Arrays.sort(answers[i]);
            if (answers[i][k-1] - answers[i][0] > 1) {
                return new Outcome(WA, "Numbers in decomposition #" + (i + 1) + "differs too much");
            }
            for (int j = 0; j < i; j++) {
                if (Arrays.equals(answers[i], answers[j])) {
                    return new Outcome(WA, "Decompositions #" + (i + 1) + " and #" + (j + 1) + " are same");
                }
            }
        }
        return new Outcome(OK, pa + " decompositions found");
    }
}

