#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    vector<int> seat(m * n);
    for (int i = 0; i < m * n; i++) {
        cin >> seat[i];
    }

    unordered_map<int, pair<int, int>> position;
    int row = 0, col = 0;
    bool isDown = true;
    for (int i = 0; i < m * n; i++) {
        position[seat[i]] = make_pair(row + 1, col + 1);
        if (isDown) {
            if (col == n - 1) {
                row++;
                isDown = false;
            }
            else {
                col++;
            }
        }
        else {
            if (col == 0) {
                row++;
                isDown = true;
            }
            else {
                col--;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        cout << position[num].first << " " << position[num].second << endl;
    }

    return 0;
}
``