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

import java.util.HashMap;
import java.util.Map;

public class Check implements Checker {
	public Outcome test(InStream inf, InStream ouf, InStream ans) {

        int n = inf.nextInt();
        int m = inf.nextInt();
        int[][] c = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                c[i][j] = inf.nextInt();
            }
        }

        String jury = ans.nextToken().toLowerCase();
        String s = ouf.nextToken().toLowerCase();
        if (s.equals("poor")) {
            String s2 = ouf.nextToken().toLowerCase();
            if (!s2.equals("kazimir")) {
                return new Outcome(Outcome.Type.PE, "<Poor> found, but <" + s2 + "> found instead of <Kazimir>");
            }
            if (jury.equals("poor")) {
                return new Outcome(Outcome.Type.OK, "Poor Kazimir");
            } else {
                return new Outcome(Outcome.Type.WA, "Solution not found, but jury have one");
            }
        }

        int actions;
        try {
            actions = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            return new Outcome(Outcome.Type.PE, "Can't parse number of turns from <" + s + ">");
        }
        if (actions < 0) {
            return new Outcome(Outcome.Type.PE, "Negative number of steps");
        }
        if (actions > 1000) {
            return new Outcome(Outcome.Type.PE, "Too many steps: " + actions + " > " + 1000);
        }
        int[] a = new int[actions];
        for (int i = 0; i < actions; i++) {
            String type = ouf.nextToken().toLowerCase();
            if (type.equals("r")) {
                int r = ouf.nextInt();
                if (!(1 <= r && r <= n)) {
                    return new Outcome(Outcome.Type.WA, "Row number " + r + " outside of [1; " + n + "]");
                }
                a[i] = r;
            } else if (type.equals("c")) {
                int col = ouf.nextInt();
                if (!(1 <= col && col <= m)) {
                    return new Outcome(Outcome.Type.WA, "Column number " + col + " outside of [1; " + m + "]");
                }
                a[i] = -col;
            } else {
                return new Outcome(Outcome.Type.PE, "<R> or <C> expected, <" + type + "> found");
            }
        }

        for (int i = 0; i < a.length; i++) {
            if (a[i] > 0) {
                int r = a[i] - 1;
                HashMap<Integer, Integer> count = new HashMap<>();
                for (int j = 0; j < m; j++) {
                    if (!count.containsKey(c[r][j])) {
                        count.put(c[r][j], 1);
                    } else {
                        count.put(c[r][j], count.get(c[r][j]) + 1);
                    }
                }
                Integer best = null;
                for (Map.Entry<Integer, Integer> e : count.entrySet()) {
                    if (e.getValue() > m / 2) {
                        if (best != null) {
                            return new Outcome(Outcome.Type.FAIL, "WTF Two of colors are greater than half");
                        }
                        best = e.getKey();
                    }
                }
                if (best == null) {
                    return new Outcome(Outcome.Type.WA, "Row " + (a[i]) + " is not recolorable");
                }
                for (int j = 0; j < m; j++) {
                    c[r][j] = best;
                }
            } else {
                int col = -a[i] - 1;
                HashMap<Integer, Integer> count = new HashMap<>();
                for (int ii = 0; ii < n; ii++) {
                    if (!count.containsKey(c[ii][col])) {
                        count.put(c[ii][col], 1);
                    } else {
                        count.put(c[ii][col], count.get(c[ii][col]) + 1);
                    }
                }
                Integer best = null;
                for (Map.Entry<Integer, Integer> e : count.entrySet()) {
                    if (e.getValue() > n / 2) {
                        if (best != null) {
                            return new Outcome(Outcome.Type.FAIL, "WTF Two of colors are greater than half");
                        }
                        best = e.getKey();
                    }
                }
                if (best == null) {
                    return new Outcome(Outcome.Type.WA, "Column " + (col + 1) + " is not recolorable");
                }
                for (int ii = 0; ii < n; ii++) {
                    c[ii][col] = best;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (c[i][j] != c[0][0]) {
                    return new Outcome(Outcome.Type.WA, "Colors of (1, 1) and (" + (i + 1) + ", " + (j + 1) + ") differ");
                }
            }
        }

        if (jury.equals("poor")) {
            return new Outcome(Outcome.Type.FAIL, "Participant found solution missed by jury");
        } else {
            return new Outcome(Outcome.Type.OK, "Great artist!");
        }
	}
}
