public static void main(String[] args) throws IOException {
		long inicio = System.currentTimeMillis();
		StringBuilder out = new StringBuilder();
		BufferedReader in;
		File archivo = new File("entrada");
		if (archivo.exists())
			in = new BufferedReader(new FileReader(archivo));
		else
			in = new BufferedReader(new InputStreamReader(System.in));

		String line = "";
		int arr[];
		int times = 1;
		while ((line = in.readLine()) != null) {
			
			inint(21);
			for (int i = 0; i < 19; i++) {
				if (i == 0)
					arr = readInts(line);
				else
					arr = readInts(in.readLine());
				for (int j = 1; j < arr.length; j++) {
					grafo[i + 1][arr[j]] = 1;
					grafo[arr[j]][i + 1] = 1;
				}
			}

			int q = Integer.parseInt(in.readLine());
			floyd(21);
			out.append("Test Set #" + times+++"\n");
			
			for (int i = 0; i < q; i++) {
				arr = readInts(in.readLine());
				if(arr[0]<10)
					out.append(" ");
				out.append(arr[0] + " to ");
				if(arr[1]<10)
					out.append(" ");
				out.append(arr[1] + ": " + grafo[arr[0]][arr[1]]+"\n");
			}
			out.append("\n");
		}
		System.out.print(out);
		if (archivo.exists())
			System.out.println("Tiempo transcurrido : "
					+ (System.currentTimeMillis() - inicio) + " milisegundos.");
	}