public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int nCases = Integer.parseInt(in.readLine().trim());
		for (int nCase = 1; nCase <= nCases; nCase++) {
			in.readLine();
			a = new char[4][];
			for (int i = 0; i < 4; i++)
				a[i] = in.readLine().trim().toCharArray();
			score = 0;
			int queries = Integer.parseInt(in.readLine().trim());
			for (int i = 0; i < queries; i++) {
				founded = false;
				u = new boolean[4][4];
				word = in.readLine().trim();
				solve();
			}
			out.append("Score for Boggle game #" + nCase + ": " + score + "\n");
		}
		System.out.print(out);
	}