import java.util.Arrays;

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 {

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		int n = inf.nextInt();
		String s = inf.nextToken();
		
		String juryAns = ans.nextToken(), partAns = ouf.nextToken();
		
		if (partAns.length() < juryAns.length()) {
			return new Outcome(Type.WA, "Jury has better answer");
		}
		
		if (!containsAsSubstring(partAns, s)) {
			return new Outcome(Type.WA, "Participant's answer is not a substring of input string");
		}
		
		if (!isSemipalindrome(partAns)) {
			return new Outcome(Type.WA, "Participant's answer is not a semipalindrome");
		}
		
		if (partAns.length() > juryAns.length()) {
			return new Outcome(Type.FAIL, "Participant found better answer");
		}
		
		return new Outcome(Type.OK, "OK");
	}
	
	private boolean isSemipalindrome(String s) {
		if (s.length() <= 1) {
			return true;
		}
		
		int len = s.length();
		String firstPart = s.substring(0, len / 2), secondPart = s.substring(s.length() - len / 2, s.length());
		if (!isSemipalindrome(firstPart) || !isSemipalindrome(secondPart)) {
			return false;
		}
		
		int checkLen = (len + 1) / 2;
		String s1 = s.substring(0, checkLen), s2 = new StringBuilder(s).reverse().toString().substring(0, checkLen);
		return areEquivalent(s1, s2);
	}
	
	private boolean areEquivalent(String s1, String s2) {
		int[] mapTo = new int[26], mapFrom = new int[26];
		Arrays.fill(mapTo, -1);
		Arrays.fill(mapFrom, -1);

		int len = s1.length();
		for (int i = 0; i < len; i++) {
			int first = s1.charAt(i) - 'a', second = s2.charAt(i) - 'a';
			if (mapTo[first] == -1 && mapFrom[second] == -1) {
				mapTo[first] = second;
				mapFrom[second] = first;
			} else if (mapTo[first] == -1 || mapFrom[second] == -1) {
				return false;
			} else {
				if (mapTo[first] != second || mapFrom[second] != first) {
					return false;
				}
			}
		}
		return true;
	}

	private boolean containsAsSubstring(String s, String text) {
		int[] pref = new int[s.length()];
		for (int i = 1; i < s.length(); i++) {
			int k = pref[i - 1];
			while (k > 0 && s.charAt(i) != s.charAt(k)) {
				k = pref[k - 1];
			}
			if (s.charAt(i) == s.charAt(k)) {
				k++;
			}
			pref[i] = k;
		}
		
		int cur = 0;
		for (int i = 0; i < text.length(); i++) {
			while (cur > 0 && text.charAt(i) != s.charAt(cur)) {
				cur = pref[cur - 1];
			}
			if (text.charAt(i) == s.charAt(cur)) {
				cur++;
			}
			
			if (cur == s.length()) {
				return true;
			}
		}
		return false;
	}
}
