#include <bits/stdc++.h>
using namespace std;
int N, M, K;
int rec[2020][2020];
bool use[2020][2020];
int d[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int ab(int x) { return x > 0 ? x : -x; }
bool check(int x, int y, int k) {
  for (int i = -k; i <= k; i++) {
    int tmpx = x + i;
    int tmpy = y - k + ab(i);
    if (tmpx < 1 || tmpx > N) continue;
    if (tmpy < 1 || tmpy > M) goto next;
    if (use[tmpx][tmpy] == false) {
      use[tmpx][tmpy] = true;
      printf("%d %d\n", tmpx, tmpy);
      rec[x][y] = k;
      return true;
    }
  next:;
    tmpy = y + k - ab(i);
    if (tmpy < 1 || tmpy > M) continue;
    if (use[tmpx][tmpy] == false) {
      use[tmpx][tmpy] = true;
      printf("%d %d\n", tmpx, tmpy);
      rec[x][y] = k;
      return true;
    }
  }
  return false;
}
int main() {
  cin >> N >> M >> K;
  int x, y;
  for (int i = 1; i <= K; i++) {
    scanf("%d%d", &x, &y);
    int j = rec[x][y];
    for (int k = 0; k < 4; k++) {
      int tmpx = x + d[k][0];
      int tmpy = y + d[k][1];
      if (tmpx < 1 || tmpx > N) continue;
      if (tmpy < 1 || tmpy > M) continue;
      j = max(j, rec[tmpx][tmpy] - 1);
    }
    j = max(j, rec[x - 1][y - 1] - 2);
    j = max(j, rec[x - 1][y + 1] - 2);
    j = max(j, rec[x + 1][y + 1] - 2);
    j = max(j, rec[x + 1][y - 1] - 2);
    for (; check(x, y, j) == false; j++)
      ;
  }
  return 0;
}
