#include <bits/stdc++.h>
using namespace std;
const int maxn = 2002;
const int inf = 1000000000;
struct Tjoint {
  int fa[maxn];
  int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
};
Tjoint U[maxn], D[maxn];
bool rev;
int n, m, K;
inline bool cmp(int x1, int y1, int x2, int y2) {
  if (!rev)
    return x1 == x2 ? y1 < y2 : x1 < x2;
  else
    return y1 == y2 ? x1 < x2 : y1 < y2;
}
void work(int &x, int &y) {
  register int nx, ny, nd, xx, yy, dd, d;
  nd = inf;
  register int limd = max(x - 1, n - x);
  for (d = 0; d <= nd && d <= limd; ++d) {
    xx = x - d;
    if (xx >= 1) {
      yy = U[xx].find(y);
      dd = d + yy - y;
      if (yy <= m && (dd < nd || dd == nd && cmp(xx, yy, nx, ny)))
        nx = xx, ny = yy, nd = dd;
      yy = D[xx].find(y);
      dd = d + y - yy;
      if (yy >= 1 && (dd < nd || dd == nd && cmp(xx, yy, nx, ny)))
        nx = xx, ny = yy, nd = dd;
    }
    xx = x + d;
    if (xx <= n) {
      yy = U[xx].find(y);
      dd = d + yy - y;
      if (yy <= m && (dd < nd || dd == nd && cmp(xx, yy, nx, ny)))
        nx = xx, ny = yy, nd = dd;
      yy = D[xx].find(y);
      dd = d + y - yy;
      if (yy >= 1 && (dd < nd || dd == nd && cmp(xx, yy, nx, ny)))
        nx = xx, ny = yy, nd = dd;
    }
  }
  x = nx;
  y = ny;
  U[x].fa[y] = y + 1;
  D[x].fa[y] = y - 1;
}
int main() {
  int i, j, x, y;
  scanf("%d%d%d", &n, &m, &K);
  if (n > m) swap(n, m), rev = true;
  for (i = 1; i <= n; ++i)
    for (j = 0; j <= m + 1; ++j) {
      U[i].fa[j] = j;
      D[i].fa[j] = j;
    }
  while (K--) {
    scanf("%d%d", &x, &y);
    if (rev) swap(x, y);
    work(x, y);
    if (rev) swap(x, y);
    printf("%d %d\n", x, y);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
