#include "testlib.h"
#include <string>
#include <vector>
#include <sstream>
#include <cmath>
#include <cassert>
#include <algorithm>

using namespace std;

int main(int argc, char * argv[])
{	
    setName("checker for problem 'compression'");
    registerTestlibCmd(argc, argv);

	int N;
	N = inf.readInt();
	vector<string> words(N);
	for (int i = 0; i < N; ++i) {
		words[i] = inf.readToken();
	}
	
	long long jAns = ans.readLong();
	long long uAns = ouf.readLong();
	long long cost = 0;

	if (jAns < uAns)
		quitf(_wa, "wa: jAns < uAns");
		
	int K;
	K = ouf.readInt();
	vector<string> pref(K);
	
	for (int i = 0; i < K; ++i) {
		pref[i] = ouf.readWord();
		if (pref[i].length() > 40)
			quitf(_wa, "wa prefix %s", pref[i].c_str());
			
		cost += 1LL << (40 - pref[i].length());
	}
	
	if (cost != uAns)
		quitf(_wa, "wa: wrong cost %I64d uAns %I64d", cost, uAns);
		
	sort(pref.begin(), pref.end());
	
	for (int i = 0; i < N; ++i) {
		string p;
		bool found = false;
		for (int l = 1; l <= words[i].length(); ++l) {
			p += words[i][l-1];
			found |= binary_search(pref.begin(), pref.end(), p);
		}
		if (!found)
			quitf(_wa, "wa: word hasn't prefix");
	}
	
	if (jAns > uAns)
		quitf(_fail, "user has found better solution");
		
	quitf(_ok, "ok");
	return 0;
}
