#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool f;
int nxt[2010][2010], lst[2010][2010];
int gtnxt(int x, int y) {
  if (y == nxt[x][y]) return y;
  return nxt[x][y] = gtnxt(x, nxt[x][y]);
}
int gtlst(int x, int y) {
  if (y == lst[x][y]) return y;
  return lst[x][y] = gtlst(x, lst[x][y]);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n > m) {
    swap(n, m);
    f = true;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      nxt[i][j] = j;
      lst[i][j] = j;
    }
  }
  while (k--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (f) swap(x, y);
    int res = 1e9, ansx = 0, ansy = 0;
    for (int dis = 0; dis <= n; dis++) {
      if (dis > res) break;
      if (x + dis <= n) {
        int tmp = gtlst(x + dis, y);
        if (tmp && tmp >= 1) {
          if (y - tmp + dis < res) {
            res = y - tmp + dis;
            ansx = x + dis;
            ansy = tmp;
          } else if (y - tmp + dis == res) {
            if (!f) {
              if (make_pair(x + dis, tmp) < make_pair(ansx, ansy))
                ansx = x + dis, ansy = tmp;
            } else {
              if (make_pair(tmp, x + dis) < make_pair(ansy, ansx))
                ansx = x + dis, ansy = tmp;
            }
          }
        }
        tmp = gtnxt(x + dis, y);
        if (tmp && tmp <= m) {
          if (tmp - y + dis < res) {
            res = tmp - y + dis;
            ansx = x + dis;
            ansy = tmp;
          } else if (tmp - y + dis == res) {
            if (!f) {
              if (make_pair(x + dis, tmp) < make_pair(ansx, ansy))
                ansx = x + dis, ansy = tmp;
            } else {
              if (make_pair(tmp, x + dis) < make_pair(ansy, ansx))
                ansx = x + dis, ansy = tmp;
            }
          }
        }
      }
      if (x - dis >= 1) {
        int tmp = gtlst(x - dis, y);
        if (tmp && tmp >= 1) {
          if (y - tmp + dis < res) {
            res = y - tmp + dis;
            ansx = x - dis;
            ansy = tmp;
          } else if (y - tmp + dis == res) {
            if (!f) {
              if (make_pair(x - dis, tmp) < make_pair(ansx, ansy))
                ansx = x - dis, ansy = tmp;
            } else {
              if (make_pair(tmp, x - dis) < make_pair(ansy, ansx))
                ansx = x - dis, ansy = tmp;
            }
          }
        }
        tmp = gtnxt(x - dis, y);
        if (tmp && tmp <= m) {
          if (tmp - y + dis < res) {
            res = tmp - y + dis;
            ansx = x - dis;
            ansy = tmp;
          } else if (tmp - y + dis == res) {
            if (!f) {
              if (make_pair(x - dis, tmp) < make_pair(ansx, ansy))
                ansx = x - dis, ansy = tmp;
            } else {
              if (make_pair(tmp, x - dis) < make_pair(ansy, ansx))
                ansx = x - dis, ansy = tmp;
            }
          }
        }
      }
    }
    nxt[ansx][ansy] = ansy + 1;
    lst[ansx][ansy] = ansy - 1;
    if (f) swap(ansx, ansy);
    printf("%d %d\n", ansx, ansy);
  }
  return 0;
}
