#include <bits/stdc++.h>
using namespace std;
struct rec {
  int l, r;
};
rec f[2222][2223];
bool can[2222][2223];
int n, m, k, x, y, xx, yy;
void del(int x, int y) {
  can[x][y] = false;
  for (int i = 1; i <= m; i++) {
    f[x][i].l = f[x][i - 1].l;
    if (can[x][i - 1]) f[x][i].l = i - 1;
  }
  for (int i = m; i >= 1; i--) {
    f[x][i].r = f[x][i + 1].r;
    if (can[x][i + 1]) f[x][i].r = i + 1;
  }
  return;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      f[i][j].l = j - 1;
      f[i][j].r = j + 1;
      can[i][j] = true;
    }
  for (int i = 1; i <= n; i++) {
    f[i][m + 1].r = m + m;
  }
  while (k--) {
    int ans = n + m + n + m;
    scanf("%d%d", &x, &y);
    for (int i = 1; i <= n; i++) {
      int u = abs(i - x);
      if (can[i][y]) {
        if (ans > u) {
          ans = u;
          xx = i;
          yy = y;
        }
      } else {
        if (f[i][y].l > 0 && ans > u + abs(f[i][y].l - y)) {
          ans = u + abs(f[i][y].l - y);
          xx = i;
          yy = f[i][y].l;
        }
        if (f[i][y].r < m + 1 && ans > u + abs(f[i][y].r - y)) {
          ans = u + abs(f[i][y].r - y);
          xx = i;
          yy = f[i][y].r;
        }
      }
      if (ans == 0) break;
    }
    printf("%d %d\n", xx, yy);
    del(xx, yy);
  }
  return 0;
}
