#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') positive = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
int N, M, ansx, ansy;
int a[2005][2005], change[2005][2005];
int f1[2005 * 2005], f2[2005 * 2005];
inline void renew(int x, int y, int d, int i) {
  int yy = i % (M + 2), xx = i / (M + 2);
  if (xx > 0 && xx <= N && yy > 0 && yy <= M &&
      abs(xx - x) + abs(yy - y) <= d) {
    if (ansx == -1 || xx < ansx || (xx == ansx && yy < ansy))
      ansx = xx, ansy = yy;
  }
}
int findset1(int x) {
  if (f1[x] == x) return x;
  f1[x] = findset1(f1[x]);
  return f1[x];
}
int findset2(int x) {
  if (f2[x] == x) return x;
  f2[x] = findset2(f2[x]);
  return f2[x];
}
inline bool check(int x, int y, int d) {
  int x0, y0;
  ansx = ansy = -1;
  x0 = max(1, x - d), y0 = x - x0 + y - d;
  if (y0 > 0) renew(x, y, d, findset1(change[x0][y0]));
  x0 = max(1, x - d), y0 = d - (x - x0 - y);
  if (y0 <= M) renew(x, y, d, findset2(change[x0][y0]));
  if (ansx > 0) {
    printf("%d %d\n", ansx, ansy);
    f1[change[ansx][ansy]] = change[ansx + 1][ansy - 1];
    f2[change[ansx][ansy]] = change[ansx + 1][ansy + 1];
    return 1;
  }
  y0 = max(y - d, 1), x0 = d - (-x + y - y0);
  if (x0 <= N) renew(x, y, d, findset2(change[x0][y0]));
  y0 = min(y + d, M), x0 = d - (-x + y0 - y);
  if (x0 <= N) renew(x, y, d, findset1(change[x0][y0]));
  if (ansx > 0) {
    printf("%d %d\n", ansx, ansy);
    f1[change[ansx][ansy]] = change[ansx + 1][ansy - 1];
    f2[change[ansx][ansy]] = change[ansx + 1][ansy + 1];
    return 1;
  }
  return 0;
}
int main() {
  N = read();
  M = read();
  for (int i = 0; i < (N + 2) * (M + 2); ++i) f1[i] = f2[i] = i;
  for (int i = 0; i <= N + 1; ++i)
    for (int j = 0; j <= M + 1; ++j) change[i][j] = i * (M + 2) + j;
  int Q = read();
  while (Q--) {
    int x = read(), y = read(), d = a[x][y];
    d = max(d, a[x - 1][y] - 1), d = max(d, a[x + 1][y] - 1);
    d = max(d, a[x][y - 1] - 1), d = max(d, a[x][y + 1] - 1);
    d = max(d, a[x - 1][y - 1] - 2), d = max(d, a[x - 1][y + 1] - 2);
    d = max(d, a[x + 1][y - 1] - 2), d = max(d, a[x + 1][y + 1] - 2);
    while (!check(x, y, d)) ++d;
    a[x][y] = d;
  }
  return 0;
}
