#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[2001][2001];
int r[2001][2001];
bool check(int x, int y, int d) {
  for (int i = max(0, x - d), mi = min(x + d, n - 1); i <= mi; i++) {
    int t = d - abs(i - x);
    int j = y - t;
    if (j >= 0 && j < m && s[i][j] == 0) {
      s[i][j] = 1;
      printf("%d %d\n", i + 1, j + 1);
      r[x][y] = d;
      return true;
    }
    j = y + t;
    if (j >= 0 && j < m && s[i][j] == 0) {
      s[i][j] = 1;
      printf("%d %d\n", i + 1, j + 1);
      r[x][y] = d;
      return true;
    }
  }
  return false;
}
int main(int argc, char *argv[]) {
  int d[][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
  scanf("%d %d %d", &n, &m, &k);
  for (int j = 0; j < k; j++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    int l = r[x][y];
    for (int i = 0; i < 4; i++) {
      int xx = x + d[i][0], yy = y + d[i][1];
      if (xx >= 0 && xx < n && yy >= 0 && yy < m) l = max(l, r[xx][yy] - 1);
    }
    for (; !check(x, y, l); l++) {
    }
  }
  return 0;
}
