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

public class Check implements Checker {
	
	final int ALPH = 26;

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		int n = inf.nextInt();
		char[] c = inf.nextToken().toCharArray();
		
		int[][] pSums = new int[ALPH][n + 1];
		for (int i = 0; i < ALPH; i++) {
			for (int j = 1; j <= n; j++) {
				if (c[j - 1] - 'a' == i) {
					pSums[i][j] = 1;
				}
				pSums[i][j] += pSums[i][j - 1];
			}
		}
		
		
		int q = inf.nextInt();
		for (int i = 0; i < q; i++) {
			int k = inf.nextInt();
			char[] alph = inf.nextToken().toCharArray();
			
			int outL = ouf.nextInt(), ansL = ans.nextInt();
			
			if (outL == -1) {
				if (ansL != -1) {
					return new Outcome(Type.WA, "Participant did not find solution for query #" + (i + 1));
				}
				continue;
			}
			
			int outR = ouf.nextInt();
			
			if (outL < 1 || outL > n || outR < 1 || outR > n || outL > outR) {
				return new Outcome(Type.WA, "Incorrect bounds for query #" + (i + 1));
			}
			
			int[] count = new int[k];
			for (int j = 0; j < k; j++) {
				int ch = alph[j] - 'a';
				count[j] = pSums[ch][outR] - pSums[ch][outL - 1];
			}
			
			for (int j = 1; j < k; j++) {
				if (count[j] != count[0]) {
					return new Outcome(Type.WA, "Count of '" + alph[0] + "' is not equal to count of '" + alph[j] + "' in query #" + (i + 1));
				}
			}
			
			if (ansL == -1) {
				return new Outcome(Type.FAIL, "Participant found answer for query #" + (i + 1) + ", but jury didn't");
			}
			
			int ansR = ans.nextInt();
			
			if (outR - outL < ansR - ansL) {
				return new Outcome(Type.WA, "Jury found better answer for query #" + (i + 1));
			} else if (outR - outL > ansR - ansL) {
				return new Outcome(Type.FAIL, "Participant found better answer for query #" + (i + 1));
			}
		}
		
		return new Outcome(Type.OK, "OK");
	}
}
