#include <bits/stdc++.h>
using namespace std;
bool flag = false;
int n, m, K;
int up[2005][2005], down[2005][2005];
int Find(int p[], int x) { return p[x] != x ? p[x] = Find(p, p[x]) : x; }
void check(int x, int y, int i, int &g, int &h, int &L) {
  if (i < 1 || i > n) {
    return;
  }
  int j;
  j = Find(up[i], y);
  if (j != 0) {
    int d = abs(x - i) + abs(y - j);
    if (d < L || d == L && (!flag && (i < g || i == g && j < h) ||
                            flag && (j < h || j == h && i < g))) {
      L = d, g = i, h = j;
    }
  }
  j = Find(down[i], y);
  if (j != m + 1) {
    int d = abs(x - i) + abs(y - j);
    if (d < L || d == L && (!flag && (i < g || i == g && j < h) ||
                            flag && (j < h || j == h && i < g))) {
      L = d, g = i, h = j;
    }
  }
}
int main() {
  cin >> n >> m >> K;
  if (n > m) {
    swap(n, m);
    flag = true;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= m + 1; j++) {
      up[i][j] = down[i][j] = j;
    }
  }
  while (K--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (flag) {
      swap(x, y);
    }
    int g = -1, h = -1, L = 0x7fffffff;
    for (int i = 0; i <= L; i++) {
      check(x, y, x - i, g, h, L);
      check(x, y, x + i, g, h, L);
    }
    up[g][h] = h - 1;
    down[g][h] = h + 1;
    if (flag) {
      swap(g, h);
    }
    printf("%d %d\n", g, h);
  }
  return 0;
}
