#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int N = 2003;
struct Dsu {
  int p[N];
  int r[N];
  int mn[N];
  int mx[N];
  bool av[N];
  void init(int n) {
    av[0] = av[n + 1] = true;
    for (int i = 1; i <= n; ++i) {
      p[i] = i;
      r[i] = 1;
      mn[i] = i;
      mx[i] = i;
      av[i] = true;
    }
  }
  int find(int x) { return x != p[x] ? p[x] = find(p[x]) : x; }
  void link(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] > r[y]) swap(x, y);
    p[x] = y;
    r[y] += r[x];
    if (mn[y] > mn[x]) mn[y] = mn[x];
    if (mx[y] < mx[x]) mx[y] = mx[x];
  }
  bool available(int x) { return av[x]; }
};
Dsu s[N];
bool flag;
int x, y;
int bd, bx, by;
int n, m;
void update(int cx, int cy) {
  if (cy < 1 || cy > m) return;
  int p = abs(cx - x) + abs(cy - y);
  if (p < bd) {
    bx = cx;
    by = cy;
    bd = p;
  } else if (p == bd) {
    if ((!flag && (cx < bx || (cx == bx && cy < by))) ||
        (flag && (cy < by || (cy == by && cx < bx)))) {
      bx = cx;
      by = cy;
    }
  }
}
int main() {
  int k;
  scanf("%d%d%d", &n, &m, &k);
  flag = false;
  if (n > m) {
    swap(n, m);
    flag = true;
  }
  for (int i = 1; i <= n; ++i) s[i].init(m);
  while (k--) {
    scanf("%d%d", &x, &y);
    if (flag) swap(x, y);
    bd = bx = by = INF;
    for (int i = 0; i <= bd; ++i) {
      if (x - i > 0) {
        int cx = x - i;
        if (s[cx].available(y))
          update(cx, y);
        else {
          int p = s[cx].find(y);
          update(cx, s[cx].mn[p] - 1);
          update(cx, s[cx].mx[p] + 1);
        }
      }
      if (x + i <= n) {
        int cx = x + i;
        if (s[cx].available(y))
          update(cx, y);
        else {
          int p = s[cx].find(y);
          update(cx, s[cx].mn[p] - 1);
          update(cx, s[cx].mx[p] + 1);
        }
      }
    }
    s[bx].av[by] = false;
    if (!s[bx].av[by + 1]) s[bx].link(by, by + 1);
    if (!s[bx].av[by - 1]) s[bx].link(by, by - 1);
    if (flag) swap(bx, by);
    printf("%d %d\n", bx, by);
  }
  return 0;
}
