#include <bits/stdc++.h>
using namespace std;
int nxt[2048][2048];
int prv[2048][2048];
int main() {
  int n, m, k;
  cin >> 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;
    cin >> x >> y;
    int best_sum = 1 << 30, bx = -1, by = -1;
    for (int j = 0; j <= n && j <= best_sum; ++j) {
      if (x - j > 0) {
        int y1 = prv[y][x - j], y2 = nxt[y][x - j];
        if (y2 != 0 && abs(y2 - y) + j <= best_sum) {
          best_sum = abs(y2 - y) + j;
          by = y2;
          bx = x - j;
        }
        if (y1 != 0 && abs(y1 - y) + j <= best_sum) {
          best_sum = abs(y1 - y) + j;
          by = y1;
          bx = x - j;
        }
      }
      if (x + j <= n) {
        int y1 = prv[y][x + j], y2 = nxt[y][x + j];
        if (y1 != 0 && abs(y1 - y) + j < best_sum) {
          best_sum = abs(y1 - y) + j;
          by = y1;
          bx = x + j;
        }
        if (y2 != 0 && abs(y2 - y) + j < best_sum) {
          best_sum = abs(y2 - y) + j;
          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;
}
