#include <bits/stdc++.h>
using namespace std;
struct unit {
  int fa[2010][2010];
  int find(int x, int y) {
    return fa[x][y] == y ? y : fa[x][y] = find(x, fa[x][y]);
  }
};
struct unit g1, g2;
int n, m, k, x2, y2, nq, d1, ansx, ansy;
int a[2010][2010];
int read() {
  int ret = 0;
  char ch = getchar();
  while (ch < 48 || ch > 57) ch = getchar();
  while (ch >= 48 && ch <= 57) {
    ret = ret * 10 + ch - 48;
    ch = getchar();
  }
  return ret;
}
void update(int x, int y) {
  int d2;
  d2 = (x > x2 ? x - x2 : x2 - x) + (y > y2 ? y - y2 : y2 - y);
  if (d2 < d1 || (d2 == d1 && (x < ansx || (x == ansx && y < ansy)))) {
    ansx = x;
    ansy = y;
    d1 = d2;
  }
}
int main() {
  int i, j, d, q, p;
  n = read(), m = read(), nq = read();
  for (i = 1; i <= n; i++)
    for (j = 0; j <= m + 1; j++) {
      g1.fa[i][j] = j;
      g2.fa[i][j] = j;
    }
  for (q = 1; q <= nq; q++) {
    x2 = read(), y2 = read();
    ansx = 4001;
    ansy = 4001;
    d1 = 4001;
    d = max(a[x2][y2], max(a[x2][y2 - 1] - 1,
                           max(a[x2][y2 + 1] - 1,
                               max(a[x2 - 1][y2] - 1, a[x2 + 1][y2] - 1))));
    d = max(0, d - m);
    k = (q / m) + (m + 1) / 2;
    for (i = d; i <= k; i++) {
      if (d1 < i) break;
      if (x2 - i > 0) {
        p = g1.find(x2 - i, y2);
        if (p != 0) update(x2 - i, p);
        p = g2.find(x2 - i, y2);
        if (p != m + 1) update(x2 - i, p);
      }
      if (i != 0 && x2 + i <= n) {
        p = g1.find(x2 + i, y2);
        if (p != 0) update(x2 + i, p);
        p = g2.find(x2 + i, y2);
        if (p != m + 1) update(x2 + i, p);
      }
    }
    g1.fa[ansx][ansy] = ansy - 1;
    g2.fa[ansx][ansy] = ansy + 1;
    a[x2][y2] = d1;
    printf("%d %d\n", ansx, ansy);
  }
  return 0;
}
