#include <bits/stdc++.h>
using namespace std;
int nxt[2004][2004];
int prv[2004][2004];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      prv[j][i] = j;
      nxt[j][i] = j;
    }
  }
  for (int i = 0; i < k; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    int best_sum = 1 << 30, bx = -1, by = -1;
    for (int j = 0; j <= best_sum && j < n; ++j) {
      if (x - j > 0) {
        int y1 = prv[y][x - j], y2 = nxt[y][x - j];
        if (y2 != 0 && y2 + j - y <= best_sum) {
          best_sum = y2 + j - y;
          by = y2;
          bx = x - j;
        }
        if (y1 != 0 && y + j - y1 <= best_sum) {
          best_sum = y + j - y1;
          by = y1;
          bx = x - j;
        }
      }
      if (x + j <= n) {
        int y1 = prv[y][x + j], y2 = nxt[y][x + j];
        if (y1 != 0 && y + j - y1 < best_sum) {
          best_sum = y + j - y1;
          by = y1;
          bx = x + j;
        }
        if (y2 != 0 && y2 + j - y < best_sum) {
          best_sum = y2 + j - y;
          by = y2;
          bx = x + j;
        }
      }
    }
    printf("%d %d\n", bx, by);
    for (int j = by; prv[j][bx] == by; ++j) {
      prv[j][bx] = prv[by - 1][bx];
    }
    for (int j = by; nxt[j][bx] == by; --j) {
      nxt[j][bx] = nxt[by + 1][bx];
    }
  }
  return 0;
}
