#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, m, Q, ansx, ansy;
int mark[N][N], r[N][N];
bool chk(int x, int y) {
  for (int tx = max(1, x - r[x][y] - 1); tx <= min(n, x + r[x][y] + 1); tx++) {
    int ty, t = r[x][y] + 1 - abs(tx - x);
    ty = y - t;
    if (ty >= 1 && ty <= m && !mark[tx][ty]) {
      ansx = tx, ansy = ty;
      return 0;
    }
    ty = y + t;
    if (ty >= 1 && ty <= m && !mark[tx][ty]) {
      ansx = tx, ansy = ty;
      return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> m >> Q;
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (!mark[x][y]) {
      mark[x][y] = 1;
      printf("%d %d\n", x, y);
      continue;
    }
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        if (x + i >= 1 && x + i <= n && y + j >= 1 && y + j <= m)
          r[x][y] = max(r[x][y], r[x + i][y + j] - abs(i) - abs(j));
    while (chk(x, y)) ++r[x][y];
    mark[ansx][ansy] = 1;
    printf("%d %d\n", ansx, ansy);
  }
  return 0;
}
