#include <bits/stdc++.h>
using namespace std;
int h[2000][2000], d[2000][2000], a, b;
int solve(int x, int y, int d, int n, int m) {
  int l, r, x2;
  if (x - d >= 0)
    l = x - d;
  else
    l = 0;
  if (x + d < n)
    r = x + d;
  else
    r = n - 1;
  for (x2 = l; x2 <= r; x2++) {
    int k;
    if (x2 > x)
      k = d - (x2 - x);
    else
      k = d - (x - x2);
    if (k < 0) k = -k;
    if (y - k >= 0 && !h[x2][y - k]) {
      a = x2 + 1, b = y - k + 1;
      h[x2][y - k] = 1;
      return 1;
    } else if (y + k < m && !h[x2][y + k]) {
      a = x2 + 1, b = y + k + 1;
      h[x2][y + k] = 1;
      return 1;
    }
  }
  return 0;
}
int main() {
  int n, m, k, x, y;
  cin >> n >> m >> k;
  while (k--) {
    cin >> x >> y;
    x--, y--;
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        if (x + i >= 0 && x + i < n && y + j >= 0 && y + j < m) {
          int w = d[x + i][y + j] - (i > 0 ? i : -i) - (j > 0 ? j : -j);
          if (d[x][y] < w) d[x][y] = w;
        }
    for (; !solve(x, y, d[x][y], n, m); d[x][y]++)
      ;
    cout << a << " " << b << endl;
  }
}
