public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			String[] firstLine = br.readLine().split("\\s+");
			int n = Integer.parseInt(firstLine[0]);
			int m = Integer.parseInt(firstLine[1]);
			int k = Integer.parseInt(firstLine[2]);

			String[] secondLine = br.readLine().split("\\s+");
			S[] ss = new S[m];
			for (int i = 0; i < m; i++) {
				ss[i] = new S(Integer.parseInt(secondLine[i]));
			}

			A[] as = new A[n];
			for (int i = 0; i < n; i++) {
				String[] line = br.readLine().split("\\s+");
				int ge = Integer.parseInt(line[0]);
				int gi = Integer.parseInt(line[1]);
				int[] xs = new int[k];
				for (int j = 0; j < k; j++) {
					xs[j] = Integer.parseInt(line[j + 2]);
				}
				as[i] = new A(i, ge, gi, xs);
			}

			process(as, ss);

			for (int i = 0; i < m; i++) {
				System.out.println(ss[i].output());
			}
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}