import java.util.*;

import ru.ifmo.testlib.*;
import ru.ifmo.testlib.Outcome.Type;

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

        int n = inf.nextInt();
        int m = inf.nextInt();
        int k = inf.nextInt();
        HashSet<Integer>[] g = new HashSet[n];
        for (int i = 0; i < n; i++) {
            g[i] = new HashSet<>();
        }
        for (int i = 0; i < k; i++) {
            g[inf.nextInt() - 1].add(inf.nextInt() - 1);
        }
        int test = inf.nextInt();
        for (int t = 0; t < test; t++) {
            long a = inf.nextInt();
            long b = inf.nextInt();
            long c = inf.nextInt();
            long d = inf.nextInt();
            long[] w1 = new long[n];
            w1[0] = a;
            for (int i = 1; i < n; i++) {
                a = w1[i] = (a * b + c) % d;
            }
            long[] w2 = new long[m];
            for (int i = 0; i < m; i++) {
                a = w2[i] = (a * b + c) % d;
            }
            int jury1 = ans.nextInt();
            if (jury1 == -1) {
                int participant = ouf.nextInt();
                if (participant != -1)
                    return new Outcome(Type.WA,
                            "Expected -1, but a pair received.");
            } else {
                int jury2 = ans.nextInt();
                int part1 = ouf.nextInt();
                if (part1 == -1)
                    return new Outcome(Type.WA,
                            "Expected a pair, but -1 received.");
                int part2 = ouf.nextInt();
                if (part1 < 1 || part1 > n || part2 < 1 || part2 > m)
                    return new Outcome(Type.WA, "There are no such towers: "
                            + part1 + " " + part2);
                if (g[part1 - 1].contains(part2 - 1))
                    return new Outcome(Type.WA,
                            "There is a road between towers " + part1 + " "
                                    + part2);
                long juryAns = w1[jury1 - 1] + w2[jury2 - 1];
                long partAns = w1[part1 - 1] + w2[part2 - 1];
                if (juryAns > partAns)
                    return new Outcome(Type.WA, "Close enough... But "
                            + partAns + " is less than " + juryAns);
                if (juryAns < partAns)
                    return new Outcome(Type.FAIL, "Test #" + (t + 1)
                            + ". Participant got " + partAns + "(" + part1
                            + ", " + part2 + "), but jury has only " + juryAns);
            }
        }
        return new Outcome(Type.OK, "Ok");
    }
}
