#include <bits/stdc++.h>
using namespace std;
int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1};
int n, m, k, i, j, dis[2005][2005], vis[2005][2005], s1, s2;
bool check(int x, int y, int d, bool f = 0) {
  int i, l = max(1, x - d), r = min(n, x + d);
  for (i = l; i <= r; i++) {
    int t = d - abs(x - i);
    if (i >= 1 && i <= n && y - t >= 1 && y - t <= m && !vis[i][y - t]) {
      s1 = i;
      s2 = y - t;
      return 1;
    }
    if (i >= 1 && i <= n && y + t >= 1 && y + t <= m && !vis[i][y + t]) {
      s1 = i;
      s2 = y + t;
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int lx = -1, ly = -1;
  while (k--) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (i = max(1, x - 5); i <= min(n, x + 5); i++) {
      for (j = max(1, y - 5); j <= min(m, y + 5); j++) {
        dis[x][y] = max(dis[x][y], dis[i][j] - abs(i - x) - abs(j - y));
      }
    }
    while (!check(x, y, dis[x][y])) dis[x][y]++;
    vis[s1][s2] = 1;
    printf("%d %d\n", s1, s2);
    lx = x;
    ly = y;
  }
  return 0;
}
