#include <bits/stdc++.h>
const int fin = 0, maxn = 2003;
int N, M, K;
int L[maxn][maxn], R[maxn][maxn];
inline int getf(int *p, int x) {
  return p[x] = (p[x] != x && p[p[x]] != p[x]) ? getf(p, p[x]) : p[x];
}
int main() {
  if (fin) {
    freopen("t.in", "r", stdin);
    freopen("t.out", "w", stdout);
  }
  int i, j, x, y, ans, d, t, t0, t1, tx, td, ax, ay;
  scanf("%d%d%d", &N, &M, &K);
  for (i = 1; i <= N; ++i)
    for (j = 0; j <= M + 1; ++j) L[i][j] = R[i][j] = j;
  while (K--) {
    scanf("%d%d", &x, &y);
    for (ans = N + M, d = 0; d <= ans; ++d) {
      if (t = x - d, t >= 1) {
        t0 = getf(L[t], y), t1 = getf(R[t], y);
        if (!t0)
          if (t1 == M + 1)
            goto Lab;
          else
            tx = t1;
        else if (t1 == M + 1)
          tx = t0;
        else
          tx = y - t0 <= t1 - y ? t0 : t1;
        td = abs(tx - y);
        if (d + td < ans || d + td == ans && (t < ax || t == ax && tx < ay))
          ans = d + td, ax = t, ay = tx;
      }
    Lab:
      if (t = x + d, t <= N) {
        t0 = getf(L[t], y), t1 = getf(R[t], y);
        if (!t0)
          if (t1 == M + 1)
            continue;
          else
            tx = t1;
        else if (t1 == M + 1)
          tx = t0;
        else
          tx = y - t0 <= t1 - y ? t0 : t1;
        td = abs(tx - y);
        if (d + td < ans || d + td == ans && (t < ax || t == ax && tx < ay))
          ans = d + td, ax = t, ay = tx;
      }
    }
    printf("%d %d\n", ax, ay);
    x = ax, y = ay;
    L[x][getf(L[x], y)] = getf(L[x], y - 1);
    R[x][getf(R[x], y)] = getf(R[x], y + 1);
  }
  return 0;
}
