#include <bits/stdc++.h>
using namespace std;
int a[2002][2002];
int v[2002][2002];
int dir[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                 {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
int x, y, k, m, n;
int sol() {
  for (int i = max(1, x - k), p = min(m, x + k); i <= p; i++) {
    int tt = k - abs(x - i);
    int j = y - tt;
    if (j >= 1 && j <= n && !v[i][j]) {
      v[i][j] = 1;
      a[x][y] = k;
      printf("%d %d\n", i, j);
      return 0;
    }
    j = y + tt;
    if (j >= 1 & j <= n && !v[i][j]) {
      v[i][j] = 1;
      a[x][y] = k;
      printf("%d %d\n", i, j);
      return 0;
    }
  }
  return 1;
}
int main() {
  int t;
  scanf("%d %d %d", &m, &n, &t);
  while (t--) {
    scanf("%d %d", &x, &y);
    k = a[x][y];
    for (int i = 0; i < 8; i++) {
      int xx = x + dir[i][0];
      int yy = y + dir[i][1];
      k = max(k, a[xx][yy] - 1 - (i > 3));
    }
    while (sol()) {
      k++;
    }
  }
  return 0;
}
