#include <bits/stdc++.h>
using namespace std;
int lft[2010][2010], rght[2010][2010];
int n, m, k;
int get(int i, int j, int arr[][2010]) {
  if (j < 1 || j > m || arr[i][j] == j) return j;
  return arr[i][j] = get(i, arr[i][j], arr);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  ;
  bool sw = 0;
  if (n > m) sw = 1, swap(n, m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) lft[i][j] = rght[i][j] = j;
  while (k--) {
    int x, y;
    scanf("%d %d", &x, &y);
    ;
    if (sw) swap(x, y);
    int dif = 1e9, rx = -1, ry = -1;
    for (int i = 0; i <= max(x - 1, n - x) && i <= dif; i++) {
      if (x - i > 0) {
        int l = get(x - i, y, lft), r = get(x - i, y, rght);
        if (sw) {
          if (l > 0 &&
              (i + abs(y - l) < dif || i + abs(y - l) == dif && l <= ry))
            dif = i + abs(y - l), rx = x - i, ry = l;
          if (r <= m &&
              (i + abs(y - r) < dif || i + abs(y - r) == dif && r < ry))
            dif = i + abs(y - r), rx = x - i, ry = r;
        } else {
          if (l > 0 && i + abs(y - l) <= dif)
            dif = i + abs(y - l), rx = x - i, ry = l;
          if (r <= m &&
              (i + abs(y - r) < dif || i + abs(y - r) == dif && x - i < rx))
            dif = i + abs(y - r), rx = x - i, ry = r;
        }
      }
      if (x + i <= n) {
        int l = get(x + i, y, lft), r = get(x + i, y, rght);
        if (sw) {
          if (l > 0 &&
              (i + abs(y - l) < dif || i + abs(y - l) == dif && l < ry))
            dif = i + abs(y - l), rx = x + i, ry = l;
          if (r <= m &&
              (i + abs(y - r) < dif || i + abs(y - r) == dif && r < ry))
            dif = i + abs(y - r), rx = x + i, ry = r;
        } else {
          if (l > 0 && i + abs(y - l) < dif)
            dif = i + abs(y - l), rx = x + i, ry = l;
          if (r <= m && i + abs(y - r) < dif)
            dif = i + abs(y - r), rx = x + i, ry = r;
        }
      }
    }
    lft[rx][ry] = ry - 1;
    rght[rx][ry] = ry + 1;
    if (sw) swap(rx, ry);
    printf("%d %d\n", rx, ry);
  }
  return 0;
}
