#include <bits/stdc++.h>
using namespace std;
int r, c, n, temp1, temp2;
bool visit[2005][2005] = {false};
int dis[2005][2005];
bool check(int x, int y) {
  int up = max(x - dis[x][y], 1), down = min(x + dis[x][y], r);
  for (int i = up; i <= down; i++) {
    int t = dis[x][y] - abs(i - x);
    if (y - t > 0 && !visit[i][y - t]) {
      temp1 = i;
      temp2 = y - t;
      return false;
    }
    if (y + t <= c && !visit[i][y + t]) {
      temp1 = i;
      temp2 = y + t;
      return false;
    }
  }
  return true;
}
int main() {
  int n1, n2;
  scanf("%d %d %d", &r, &c, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &n1, &n2);
    if (!visit[n1][n2]) {
      temp1 = n1;
      temp2 = n2;
      visit[n1][n2] = true;
    } else {
      for (int a = -1; a <= 1; a++)
        for (int b = -1; b <= 1; b++) {
          if (n1 + a <= 0 || n2 + b <= 0 || n1 + a >= r || n2 + b >= c)
            continue;
          dis[n1][n2] = max(dis[n1][n2], dis[n1 + a][n2 + b] - abs(a) - abs(b));
        }
      while (check(n1, n2)) {
        dis[n1][n2]++;
      }
      visit[temp1][temp2] = true;
    }
    printf("%d %d\n", temp1, temp2);
  }
}
