import java.util.HashSet;

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

public class Check implements ru.ifmo.testlib.Checker {

	String vowels = "aeiouy";

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		// read input
		int n = inf.nextInt();
		int s = inf.nextInt();
		String[] a = new String[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = inf.nextToken();
		}

		// hash set to check if all words are from input file
		HashSet<String> hs = new HashSet<String>();
		for (int i = 0; i < a.length; i++) {
			hs.add(a[i]);
		}

		// read first word of ans
		String ans1 = ans.nextToken();
		String firstLine = null;
		String secondLine = null;
		firstLine = ouf.nextLine().trim();
		if (ans1.equals("Impossible")) {
			if (firstLine.equals("Impossible")) {
				return new Outcome(Type.OK, "Impossible");
			}
		}
		if (firstLine.equals("Impossible")) {
			return new Outcome(Type.WA, "Solution not found");
		}
		secondLine = ouf.nextLine().trim();
		String[] first, second;
		try {
			first = firstLine.split(" ");
			second = secondLine.split(" ");
		} catch (Throwable e) {
			return new Outcome(Type.PE, "Strange output");
		}
		check(first, s, hs);
		check(second, s, hs);
		if (first[first.length - 1].equals(second[second.length - 1])) {
			return new Outcome(Type.WA, "last words are equal: "
					+ first[first.length - 1]);
		}
		if (!check2(first[first.length - 1], second[second.length - 1])) {
			return new Outcome(Type.WA, "ending words do not rhyme");
		}
		if (ans1.equals("Impossible")) {
			return new Outcome(Type.FAIL, "Participant is a better poet");
		}
		return new Outcome(Type.OK, "output for this test is one of the best");
	}

	private boolean check2(String s1, String s2) {
	  int lastvow1 = 0;
	  for (int i = 0; i < s1.length(); i++) {
	  	if (vowels.indexOf(s1.charAt(i)) >= 0) {
	  	  lastvow1 = i;
	  	}
	  }
	  int lastvow2 = 0;
	  for (int i = 0; i < s2.length(); i++) {
	  	if (vowels.indexOf(s2.charAt(i)) >= 0) {
	  	  lastvow2 = i;
	  	}
	  }
	  return s1.substring(lastvow1).equals(s2.substring(lastvow2));
	}

	private void check(String[] line, int s, HashSet<String> hs) {
		int v = 0;
		for (String str : line) {
			if (!hs.contains(str)) {
				throw new Outcome(Type.PE, "unknown word: " + str);
			}
			for (int i = 0; i < str.length(); i++) {
				if (vowels.indexOf(str.charAt(i)) >= 0) {
					v++;
				}
			}
		}
		if (v != s) {
			throw new Outcome(Type.WA,
					"wrong number of vowels int line: expected " + s
							+ "; found " + v);
		}
	}
}
