#include <bits/stdc++.h>
using namespace std;
int n, m, k, a, b, x, y, d[2010][2010], v[2010][2010];
bool sol(int x, int y, int k) {
  int l = max(1, x - k), r = min(n, x + k);
  for (int i = l; i <= r; i++) {
    int t = k - abs(i - x);
    if (y - t > 0 && !v[i][y - t]) return a = i, b = y - t, 1;
    if (y + t <= m && !v[i][y + t]) return a = i, b = y + t, 1;
  }
  return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    for (int ii = -3; ii <= 3; ii++)
      for (int jj = -3; jj <= 3; jj++) {
        if (x + ii > 0 && x + ii <= n && y + jj > 0 && y + jj <= m)
          d[x][y] = max(d[x][y], d[x + ii][y + jj] - abs(ii) - abs(jj));
      }
    while (!sol(x, y, d[x][y])) d[x][y]++;
    printf("%d %d\n", a, b);
    v[a][b] = 1;
  }
  return 0;
}
