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