#include <bits/stdc++.h>
using namespace std;
int le[4000][4000], ri[4000][4000];
int rot, n, m, k, ans, x, y, ax, ay;
int findle(int i, int j) {
  if (le[i][j] != j) le[i][j] = findle(i, le[i][j]);
  return le[i][j];
}
int findri(int i, int j) {
  if (ri[i][j] != j) ri[i][j] = findri(i, ri[i][j]);
  return ri[i][j];
}
void upd_ans(int xx, int yy) {
  if (!(1 <= yy && yy <= m)) return;
  int dist = abs(x - xx) + abs(y - yy);
  if (ans > dist) {
    ans = dist;
    ax = xx;
    ay = yy;
  }
  if (ans == dist) {
    if (!rot && make_pair(ax, ay) > make_pair(xx, yy)) ax = xx, ay = yy;
    if (rot && make_pair(ay, ax) > make_pair(yy, xx)) ax = xx, ay = yy;
  }
}
int main() {
  rot = false;
  scanf("%d%d%d", &n, &m, &k);
  if (n > m) {
    swap(n, m);
    rot = true;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= m + 1; ++j) le[i][j] = ri[i][j] = j;
  for (int it = 0; it < k; ++it) {
    scanf("%d%d", &x, &y);
    if (rot) swap(x, y);
    ans = (1 << 30);
    ax = -1, ay = -1;
    for (int d = 0; d <= ans; ++d) {
      if (x - d >= 1) {
        int yy = findle(x - d, y);
        upd_ans(x - d, yy);
        yy = findri(x - d, y);
        upd_ans(x - d, yy);
      }
      if (x + d <= n) {
        int yy = findle(x + d, y);
        upd_ans(x + d, yy);
        yy = findri(x + d, y);
        upd_ans(x + d, yy);
      }
    }
    le[ax][ay] = ay - 1;
    ri[ax][ay] = ay + 1;
    if (rot) swap(ax, ay);
    printf("%d %d\n", ax, ay);
  }
  return 0;
}
