#include <bits/stdc++.h>
using namespace std;
int ar[2005][2005], r[2005][2005], l[2005][2005];
int n, m, a, b, _minx, _miny, d;
inline void edit(int x, int y) {
  r[x][m + 1] = m + 1;
  l[x][0] = 0;
  for (int i = y; ar[x][i]; ++i) l[x][i] = l[x][i - 1];
  for (int i = y; ar[x][i]; --i) r[x][i] = r[x][i + 1];
}
inline void dist(int x, int y) {
  int l = abs(a - x) + abs(b - y);
  if (y >= 1 && y <= m && (l < d || l == d && (x < _minx))) {
    d = l;
    _minx = x;
    _miny = y;
  }
}
inline void read(int &x) {
  char ch;
  x = 0;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar())
    ;
}
int main() {
  int i, j;
  int k;
  scanf(" %d %d %d", &n, &m, &k);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) l[i][j] = r[i][j] = j;
  for (i = 1; i <= k; i++) {
    read(a);
    read(b);
    d = 1000000;
    for (j = 0; j <= d; j++) {
      if (a - j > 0) dist(a - j, l[a - j][b]);
      if (a - j > 0) dist(a - j, r[a - j][b]);
      if (a + j <= n) dist(a + j, l[a + j][b]);
      if (a + j <= n) dist(a + j, r[a + j][b]);
    }
    printf("%d %d\n", _minx, _miny);
    ar[_minx][_miny] = 1;
    edit(_minx, _miny);
  }
  return 0;
}
