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