public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		int t = 1;
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] ab = readInts(line);
			if (ab[0] == 0 && ab[1] == 0)
				break;
			int ans = 0;
			int[] a = readInts(in.readLine());
			int[] b = readInts(in.readLine());
			if (a.length > b.length)
				ans = LCS(a, b);
			else
				ans = LCS(b, a);
			out.append("Twin Towers #" + t++ + "\nNumber of Tiles : " + ans
					+ "\n\n");

		}
		System.out.print(out);
	}