import java.util.HashSet;

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) {
		char[] jString = inf.nextToken().toCharArray();
		char[] pString = jString.clone();
		int k = inf.nextInt();
		char[] replaces = new char[26];
		for (int i = 0; i < k; i++) {
			replaces[inf.nextToken().charAt(0) - 'a'] = inf.nextToken().charAt(0);
		}
		int jAns = ans.nextInt();
		int pAns = ouf.nextInt();
		if (jAns != -1) {
			HashSet<Integer> was = new HashSet<Integer>();
			for (int i = 0; i < jAns; i++) {
				int t = ans.nextInt() - 1;
				if (was.contains(t))
					return new Outcome(Type.FAIL, "Jury is stupid, double replace at position " + t);
				if (t < 0)
					return new Outcome(Type.FAIL, "Jury is stupid, " + t + " is less, than zero");
				if (t >= jString.length)
					return new Outcome(Type.FAIL, "Jury is stupid, " + t + " is greater, than length of string");
				was.add(t);
				if (replaces[jString[t] - 'a'] == 0) {
					return new Outcome(Type.FAIL, "Jury is stupid, there is no replace for " + jString[t]);
				}
				jString[t] = replaces[jString[t] - 'a'];
			}
			for (int i = 0; i < jString.length / 2; i++) {
				if (jString[i] != jString[jString.length - i - 1]) {
					return new Outcome(Type.FAIL, "Difference at position " + i + " " + (jString.length - i - 1));
				}
			}
		}
		
		if (pAns != -1) {
			HashSet<Integer> was = new HashSet<Integer>();
			for (int i = 0; i < pAns; i++) {
				int t = ouf.nextInt() - 1;
				if (was.contains(t))
					return new Outcome(Type.WA, "Double replace at position " + t);
				if (t < 0)
					return new Outcome(Type.WA, t + " is less, than zero");
				if (t >= pString.length)
					return new Outcome(Type.WA, t + " is greater, than length of string");
				was.add(t);
				if (replaces[pString[t] - 'a'] == 0) {
					return new Outcome(Type.WA, "There is no replace for " + pString[t]);
				}
				pString[t] = replaces[pString[t] - 'a'];
			}
			for (int i = 0; i < pString.length / 2; i++) {
				if (pString[i] != pString[pString.length - i - 1]) {
					return new Outcome(Type.WA, "Difference at position " + i + " " + (pString.length - i - 1));
				}
			}
		}
		
		if (pAns == jAns) {
			return new Outcome(Type.OK, "OK");
		}
		
		if (pAns == -1) {
			return new Outcome(Type.WA, "Contestan hasn't found the right solution");
		}
		
		if (jAns == -1) {
			return new Outcome(Type.FAIL, "Contestant has found the solution, but jury hasn't");
		}
		
		if (jAns < pAns) {
			return new Outcome(Type.WA, "Contestant's solution isn't optimal");
		}
		
		if (jAns > pAns) {
			return new Outcome(Type.FAIL, "Jury's solution isn't optimal");
		}
		
		return new Outcome(Type.FAIL, "Something bad has happened");
	}
}
