#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int _N = 2010;
int n, m, k, lop[_N][_N], rop[_N][_N];
inline int myAbs(int a) { return (a >= 0) ? a : -a; }
inline void updOpt(int d, int x, int y, int &_d, int &_x, int &_y) {
  if (d < _d)
    _d = d, _x = x, _y = y;
  else if (d == _d) {
    if (x < _x)
      _d = d, _x = x, _y = y;
    else if ((x == _x) && (y < _y))
      _d = d, _x = x, _y = y;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) lop[i][j] = rop[i][j] = j;
  for (int _it = 0; _it < k; _it++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    int _d = INF, _x, _y;
    for (int i = x + 1 - 1; i >= 0; i--) {
      if (x - i > _d) break;
      if (lop[i][y] != -1)
        updOpt(myAbs(x - i) + myAbs(y - lop[i][y]), i, lop[i][y], _d, _x, _y);
      if (rop[i][y] != -1)
        updOpt(myAbs(x - i) + myAbs(y - rop[i][y]), i, rop[i][y], _d, _x, _y);
    }
    for (int i = x; i < n; i++) {
      if (i - x > _d) break;
      if (lop[i][y] != -1)
        updOpt(myAbs(x - i) + myAbs(y - lop[i][y]), i, lop[i][y], _d, _x, _y);
      if (rop[i][y] != -1)
        updOpt(myAbs(x - i) + myAbs(y - rop[i][y]), i, rop[i][y], _d, _x, _y);
    }
    cout << _x + 1 << ' ' << _y + 1 << endl;
    for (int j = _y + 1 - 1; j >= 0; j--) {
      if ((j != _y) && (rop[_x][j] == j)) break;
      rop[_x][j] = (j == m - 1) ? -1 : rop[_x][j + 1];
    }
    for (int j = _y; j < m; j++) {
      if ((j != _y) && (lop[_x][j] == j)) break;
      lop[_x][j] = (j == 0) ? -1 : lop[_x][j - 1];
    }
  }
  return 0;
}
