public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		int times = 1;
		do {
			line = in.readLine();
			if (line == null || line.length() == 0)
				break;
			int tests = Integer.parseInt(line.trim());
			for (int i = 0; i < tests; i++) {
				int build = Integer.parseInt(in.readLine().trim());
				Floyd f = new Floyd();
				f.inint(build);
				int paths = Integer.parseInt(in.readLine().trim()), uv[];
				for (int j = 0; j < paths; j++) {
					uv = retInts(in.readLine());
					f.d[uv[0]][uv[1]] = 1;
					f.d[uv[1]][uv[0]] = 1;
				}
				uv = retInts(in.readLine());
				int start = uv[0], end = uv[1];
				f.floyd();
				long max = 0;
				for (int j = 0; j < build; j++) 
					max = Math.max(max, f.d[start][j]+f.d[j][end]);
				out.append("Case "+times++ + ": "+max+"\n");
			}
		} while (line != null && line.length() != 0);
		System.out.print(out); 
	}