#include <bits/stdc++.h>
bool vis[2005][2005];
int mx[2005][2005];
inline void upd(int &x, int y) {
  if (x < y) x = y;
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  while (k--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (!vis[x][y]) {
      printf("%d %d\n", x + 1, y + 1);
      vis[x][y] = true;
      continue;
    }
    for (int d = 1; d <= 5; d++) {
      for (int i = std::max(0, x - d); i < std::min(n, x + d + 1); i++) {
        int rem = d - ((x - i) < 0 ? -(x - i) : (x - i));
        int l = y - rem, r = y + rem;
        if (((i) >= 0 && (i) < n && (l) >= 0 && (l) < m))
          upd(mx[x][y], mx[i][l] - d);
        if (((i) >= 0 && (i) < n && (r) >= 0 && (r) < m))
          upd(mx[x][y], mx[i][r] - d);
      }
    }
    for (int d = mx[x][y] + 1;; d++) {
      bool f = false;
      for (int i = std::max(0, x - d); i < std::min(n, x + d + 1); i++) {
        int rem = d - ((x - i) < 0 ? -(x - i) : (x - i));
        int l = y - rem, r = y + rem;
        if (((i) >= 0 && (i) < n && (l) >= 0 && (l) < m) && !vis[i][l]) {
          f = true;
          printf("%d %d\n", i + 1, l + 1);
          vis[i][l] = true;
          break;
        }
        if (((i) >= 0 && (i) < n && (r) >= 0 && (r) < m) && !vis[i][r]) {
          f = true;
          printf("%d %d\n", i + 1, r + 1);
          vis[i][r] = true;
          break;
        }
      }
      if (f) {
        mx[x][y] = d - 1;
        break;
      }
    }
  }
  return 0;
}
