public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int M = scanner.nextInt();
        int N = scanner.nextInt();
        int[][] memory = new int[M][N];
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                memory[i][j] = scanner.nextInt();
            }
        }

        int Q = scanner.nextInt();
        for (int q = 0; q < Q; q++) {
            int number = scanner.nextInt();
            boolean found = false;

            int i = M - 1;
            int j = 0;
            while (i > -1 && j < N) {
                if (memory[i][j] < number) {
                    j++;
                } else if (memory[i][j] > number) {
                    i--;
                } else {
                    System.out.println(i + " " + j);
                    found = true;
                    break;
                }
            }
            if (!found) {
                System.out.println(-1 + " " + -1);
            }
        }
    }