#include <bits/stdc++.h>
using namespace std;
int n, m, k, rx, ry, x, y, ret;
int ll[2005][2005], rr[2005][2005];
bool rot;
int findl(int x, int y) {
  return ll[x][y] == y ? y : ll[x][y] = findl(x, ll[x][y]);
}
int findr(int x, int y) {
  return rr[x][y] == y ? y : rr[x][y] = findr(x, rr[x][y]);
}
void solve(int nx, int ny) {
  if (ny < 1 || ny > m) return;
  int dis = abs(nx - x) + abs(ny - y);
  if (rot) swap(nx, ny);
  if (dis < ret || (dis == ret && (nx < rx || (nx == rx && ny < ry))))
    ret = dis, rx = nx, ry = ny;
}
int main() {
  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++) ll[i][j] = rr[i][j] = j;
  while (k--) {
    scanf("%d%d", &x, &y);
    if (rot) swap(x, y);
    ret = 0x73737373;
    for (int i = 0; i <= ret; i++) {
      if (x - i >= 1) {
        solve(x - i, findl(x - i, y));
        solve(x - i, findr(x - i, y));
      }
      if (x + i <= n) {
        solve(x + i, findl(x + i, y));
        solve(x + i, findr(x + i, y));
      }
    }
    printf("%d %d\n", rx, ry);
    if (rot) swap(rx, ry);
    ll[rx][ry] = findl(rx, ry - 1);
    rr[rx][ry] = findr(rx, ry + 1);
  }
  return 0;
}
