#include <bits/stdc++.h>
int used[2000][2000];
int d[2000][2000];
int a, b;
int solve(int x, int y, int d, int n, int m) {
  int l = x - d >= 0 ? x - d : 0;
  int r = x + d < n ? x + d : n - 1;
  int x2;
  for (x2 = l; x2 <= r; x2++) {
    int k = d - (x2 > x ? x2 - x : x - x2);
    if (k < 0) k = -k;
    if (y - k >= 0 && !used[x2][y - k]) {
      a = x2 + 1, b = y - k + 1;
      used[x2][y - k] = 1;
      return 1;
    } else if (y + k < m && !used[x2][y + k]) {
      a = x2 + 1, b = y + k + 1;
      used[x2][y + k] = 1;
      return 1;
    }
  }
  return 0;
}
int main() {
  int i, j, n, m, k, x, y;
  scanf("%d%d%d", &n, &m, &k);
  while (k-- > 0) {
    scanf("%d%d", &x, &y);
    x--, y--;
    for (i = -1; i <= 1; i++)
      for (j = -1; j <= 1; j++)
        if (x + i >= 0 && x + i < n && y + j >= 0 && y + j < m) {
          int dist = d[x + i][y + j] - (i > 0 ? i : -i) - (j > 0 ? j : -j);
          if (d[x][y] < dist) d[x][y] = dist;
        }
    for (; !solve(x, y, d[x][y], n, m); d[x][y]++)
      ;
    printf("%d %d\n", a, b);
  }
  return 0;
}
