#include <bits/stdc++.h>
using namespace std;
int d[2048][2048], n, m, i, j, k, x, y, D, X, Y;
int v[2048][2048];
bool check(int x, int y, int D) {
  int i, j, L = max(1, x - D), R = min(n, x + D);
  for (i = L; i <= R; i++) {
    j = D - abs(i - x);
    if (y - j > 0 && !v[i][y - j]) {
      v[i][y - j] = true;
      d[x][y] = D;
      printf("%d %d\n", i, y - j);
      return 0;
    }
    if (y + j <= m && !v[i][y + j]) {
      v[i][y + j] = true;
      d[x][y] = D;
      printf("%d %d\n", i, y + j);
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  while (k--) {
    scanf("%d%d", &x, &y);
    D = 0;
    for (i = -1; i <= 1; i++)
      for (j = -1; j <= 1; j++) {
        X = x + i, Y = y + j;
        if (1 <= X && X <= n && 1 <= Y && Y <= m)
          D = max(D, d[X][Y] - abs(i) - abs(j));
      }
    while (check(x, y, D)) D++;
  }
  return 0;
}
