public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("src/utilities/kdtree.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"src/utilities/kdtree.out")));
		Scanner in = new Scanner(f);
		// Scanner skp=new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt(), k = in.nextInt();
			KDTree kdTree = new KDTree(k, n, out);
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < k; j++) {
					kdTree.myPoints[i].coords[j] = in.nextInt();
				}
			}
			// initialize
			kdTree.work();
			// output
			int cin = in.nextInt();
			for (int ci = 0; ci < cin; ci++) {
				for (int i = 0; i < k; i++) {
					kdTree.aim.coords[i] = in.nextInt();
				}
				kdTree.KNN(in.nextInt());
				// skp.nextLine();
			}
		}
		out.close();

		/*
		 * 15 2 1 3 2 7 3 5 4 2 5 3 5 7 6 6 7 3 8 7 11 7 10 4 9 2 11 3 8 1 10 1
		 * 1 1 3 10
		 */
	}