public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int totalArestas = sc.nextInt();
		int numCase = 1;

		while (totalArestas != 0) {
			List<Integer> vertices = new ArrayList<Integer>();
			int[][] arestas = new int[totalArestas * 2 + 10][2];

			for (int i = 0; i < totalArestas; i++) {
				int no1 = sc.nextInt();
				int no2 = sc.nextInt();

				if (!vertices.contains(no1))
					vertices.add(no1);

				if (!vertices.contains(no2))
					vertices.add(no2);

				arestas[i][0] = no1;
				arestas[i][1] = no2;
			}

			int noInicial = sc.nextInt();
			int ttl = sc.nextInt();

			while (!(noInicial == 0 && ttl == 0)) {
				System.out.println("Case " + numCase + ": "
						+ naoAlcancaveis(vertices, arestas, noInicial, ttl)
						+ " nodes not reachable from node " + noInicial
						+ " with TTL = " + ttl + ".");
				numCase++;
				noInicial = sc.nextInt();
				ttl = sc.nextInt();
			}
			
			totalArestas = sc.nextInt();
		}
		sc.close();
	}