#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch;
  bool flag = false;
  int a = 0;
  while (!(((ch = getchar()) >= '0' && ch <= '9') | ch == '-'))
    ;
  if (ch != '-')
    a = a * 10 + ch - '0';
  else
    flag = true;
  while ((ch = getchar()) >= '0' && ch <= '9') a = a * 10 + ch - '0';
  if (flag) a = -a;
  return a;
}
void write(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
const int maxn = int(2e3) + 10;
const int INF = int(2e9);
int n, m, k;
bool swp;
int l[maxn][maxn], r[maxn][maxn];
bool mark[maxn][maxn];
int dist, bestx, besty;
int _find(int fa[][maxn], int x, int y) {
  if (!mark[x][y])
    return y;
  else
    return fa[x][y] = _find(fa, x, fa[x][y]);
}
void check(int dis, int x, int y) {
  if (dis > dist)
    return;
  else if (dis < dist) {
    dist = dis;
    bestx = x;
    besty = y;
    return;
  } else if (!swp && (x < bestx || x == bestx && y < besty))
    bestx = x, besty = y;
  else if (swp && (y < besty || y == besty && x < bestx))
    bestx = x, besty = y;
  return;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n > m) {
    std::swap(n, m);
    swp = true;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      l[i][j] = j - 1, r[i][j] = j + 1;
    }
  for (int per = 1; per <= k; per++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (swp) std::swap(x, y);
    dist = INF;
    for (int i = 0; i <= dist; i++) {
      if (x - i >= 1) {
        int pos;
        pos = _find(l, x - i, y);
        if (pos >= 1) check(i + y - pos, x - i, pos);
        pos = _find(r, x - i, y);
        if (pos <= m) check(i - y + pos, x - i, pos);
      }
      if (x + i <= n) {
        int pos;
        pos = _find(l, x + i, y);
        if (pos >= 1) check(i + y - pos, x + i, pos);
        pos = _find(r, x + i, y);
        if (pos <= m) check(i - y + pos, x + i, pos);
      }
    }
    if (swp)
      printf("%d %d\n", besty, bestx);
    else
      printf("%d %d\n", bestx, besty);
    mark[bestx][besty] = true;
  }
  return 0;
}
