#include <bits/stdc++.h>
using namespace std;
int dx[10] = {0, 0, -1, 1, -1, -1, 1, 1};
int dy[10] = {-1, 1, 0, 0, -1, 1, -1, 1};
int a[3000][3000], n, m;
bool b[3000][3000];
bool ans(int x, int y, int d) {
  int j, t;
  for (int i = max(1, x - d); i <= min(x + d, n); i++) {
    t = d - abs(i - x);
    j = y - t;
    for (int k = 0; k < 2; k++) {
      if (j > 0 && j <= m && b[i][j] == 0) {
        b[i][j] = 1;
        cout << i << ' ' << j << endl;
        a[x][y] = d;
        return 0;
      }
      j += 2 * t;
    }
  }
  return 1;
}
int main() {
  int x, y, d, k;
  cin >> n >> m >> k;
  while (k--) {
    cin >> x >> y;
    d = a[x][y];
    for (int i = 0; i < 8; i++) {
      d = max(d, a[x + dx[i]][y + dy[i]] - 1 - (i > 3));
    }
    while (ans(x, y, d)) d++;
  }
}
