#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f[2222][2222], g, h, j, k, l, m, n, x, y, s[2222][2222];
bool ok(int x, int y, int k) {
  int l = max(1, x - k), r = min(x + k, a), d;
  for (int i = l; i <= r; ++i) {
    d = k - abs(i - x);
    if (y - d > 0 && !f[i][y - d]) {
      g = i;
      h = y - d;
      return 1;
    }
    if (y + d <= b && !f[i][y + d]) {
      g = i;
      h = y + d;
      return 1;
    }
  }
  return 0;
}
int main() {
  cin >> a >> b >> k;
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    for (int j = -2; j <= 2; ++j) {
      for (int k = -2; k <= 2; ++k) {
        if (x + j < 1 || x + j > a || y + k < 1 || y + k > b) continue;
        s[x][y] = max(s[x][y], s[x + j][y + k] - abs(j) - abs(k));
      }
    }
    while (!ok(x, y, s[x][y])) s[x][y]++;
    f[g][h] = 1;
    cout << g << " " << h << endl;
  }
}
