#include <bits/stdc++.h>
using namespace std;
int n, m, k, ansx, ansy, vis[2010][2010], dis[2010][2010];
bool check(int x, int y) {
  if (x < 1 || x > n) return false;
  if (y < 1 || y > m) return false;
  return true;
}
bool fin(int x, int y) {
  int st = max(1, x - dis[x][y]), en = min(n, x + dis[x][y]);
  for (int i = st; i <= en; ++i) {
    int s = dis[x][y] - abs(i - x);
    if (check(i, y - s) && !vis[i][y - s]) {
      ansx = i;
      ansy = y - s;
      vis[i][y - s] = true;
      return false;
    }
    if (check(i, y + s) && !vis[i][y + s]) {
      ansx = i;
      ansy = y + s;
      vis[i][y + s] = true;
      return false;
    }
  }
  return true;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (!vis[x][y]) {
      vis[x][y] = true;
      printf("%d %d\n", x, y);
    } else {
      for (int i = -1; i <= 1; ++i)
        for (int j = -1; j <= 1; ++j) {
          if (!check(x + i, y + j)) continue;
          dis[x][y] = max(dis[x][y], dis[x + i][y + j] - !(!i) - !(!j));
        }
      while (fin(x, y)) dis[x][y]++;
      printf("%d %d\n", ansx, ansy);
    }
  }
  return 0;
}
