#include <bits/stdc++.h>
int N, M, Q, f[2001][2001], right_link[2001][2001];
bool swapped;
int F(int *f, int x) { return f[x] == x ? x : f[x] = F(f, f[x]); }
void remove(int x, int y) {
  int L = F(f[x], y - 1), R = right_link[x][y];
  f[x][y] = L;
  right_link[x][L] = R;
}
std::pair<int, int> left_and_right(int x, int y) {
  int L = F(f[x], y), R = right_link[x][L];
  return {L, R};
}
inline int abs(int x) { return x < 0 ? -x : x; }
int udis, ux, uy;
void update(int x, int y, int x0, int y0) {
  int dis = abs(x - x0) + abs(y - y0);
  if (swapped) std::swap(x0, y0);
  if (dis < udis || dis == udis && (x0 < ux || (x0 == ux && y0 < uy))) {
    udis = dis;
    ux = x0;
    uy = y0;
  }
}
void query(int x, int y) {
  udis = 1000000000, ux = 0, uy = 0;
  for (int d = 0; d <= udis; d++) {
    if (x - d >= 1) {
      std::pair<int, int> g = left_and_right(x - d, y);
      if (g.first != 0) update(x, y, x - d, g.first);
      if (g.second != M + 1) update(x, y, x - d, g.second);
    }
    if (d && x + d <= N) {
      std::pair<int, int> g = left_and_right(x + d, y);
      if (g.first != 0) update(x, y, x + d, g.first);
      if (g.second != M + 1) update(x, y, x + d, g.second);
    }
  }
  printf("%d %d\n", ux, uy);
  if (swapped)
    remove(uy, ux);
  else
    remove(ux, uy);
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  if (N > M) {
    std::swap(N, M);
    swapped = true;
  }
  for (int i = 1; i <= N; i++)
    for (int j = 0; j <= M; j++) {
      f[i][j] = j;
      right_link[i][j] = j + 1;
    }
  for (int i = 1, x, y; i <= Q; i++) {
    scanf("%d%d", &x, &y);
    if (swapped) std::swap(x, y);
    query(x, y);
  }
  return 0;
}
