#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int seat[2000 + 10][2000 + 10];
int xx, yy;
int c;
long long full_seat(int xxx, int yyy) {
  int myx, myy;
  int layer = seat[xxx][yyy];
  bool prob = true;
  while (prob) {
    myx = max((xxx - layer), 1);
    while (prob && (myx <= xxx + layer) && (0 < myx) && (myx <= n)) {
      myy = yyy - (layer - abs(myx - xxx));
      if ((0 < myy) && (myy <= m) && !seat[myx][myy]) {
        printf("%d %d\n", myx, myy);
        seat[myx][myy] = 1;
        prob = false;
      } else {
        myy = yyy + (layer - abs(myx - xxx));
        if ((0 < myy) && (myy <= m) && !seat[myx][myy]) {
          printf("%d %d\n", myx, myy);
          seat[myx][myy] = 1;
          prob = false;
        }
      }
      myx++;
    }
    layer++;
  }
  return layer - 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &xx, &yy);
    if (!seat[xx][yy]) {
      seat[xx][yy]++;
      printf("%d %d\n", xx, yy);
    } else {
      for (int i = -1; i < 2; i++)
        for (int j = -1; j < 2; j++)
          if ((0 < xx - i) && (xx - i <= n) && (0 < yy - j) && (yy - j <= m))
            seat[xx][yy] =
                max(seat[xx][yy], (seat[xx - i][yy - j] - abs(i) - abs(j)));
      seat[xx][yy] = full_seat(xx, yy);
    }
  }
}
