#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 1e18;
inline char nc() {
  static char buf[100005], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  char ch = getchar();
  int sum = 0;
  int f = 0;
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
  return f ? -sum : sum;
}
inline long long readll() {
  char ch = getchar();
  int sum = 0;
  int f = 0;
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
  return f ? -sum : sum;
}
const int maxn = 2005;
int n, m, q;
int v[maxn][maxn];
int d[maxn][maxn];
int ansx, ansy;
inline bool check(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
inline bool spread(int x, int y) {
  int l = max(x - d[x][y], 1), r = min(x + d[x][y], n);
  for (int i = l; i <= r; i++) {
    int tmp = d[x][y] - abs(i - x);
    if (y - tmp >= 1 && !v[i][y - tmp]) {
      ansx = i;
      ansy = y - tmp;
      return false;
    }
    if (y + tmp <= m && !v[i][y + tmp]) {
      ansx = i;
      ansy = y + tmp;
      return false;
    }
  }
  return true;
}
int main() {
  n = read();
  m = read();
  q = read();
  while (q--) {
    int x, y;
    x = read();
    y = read();
    if (!v[x][y]) {
      printf("%d %d\n", x, y);
      v[x][y] = 1;
      continue;
    }
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++) {
        int xx = x + i, yy = y + j;
        if (!check(xx, yy)) continue;
        d[x][y] = max(d[x][y], d[xx][yy] - abs(i) - abs(j));
      }
    while (spread(x, y)) d[x][y]++;
    v[ansx][ansy]++;
    printf("%d %d\n", ansx, ansy);
  }
  return 0;
}
