#include <bits/stdc++.h>
using namespace std;
int f_max(int x, int y) { return x > y ? x : y; }
int f_min(int x, int y) { return x < y ? x : y; }
int f_abs(int x) {
  if (x > 0) return x;
  return -x;
}
void swap(int &x, int &y) {
  int t;
  t = x, x = y, y = t;
}
bool visit[2001][2001];
int mp[2001][2001][2];
int n, m;
int find(int x, int y, int z) {
  if (mp[x][y][z] == 0 || mp[x][y][z] == m + 1 || mp[x][y][z] == y)
    return mp[x][y][z];
  return mp[x][y][z] = find(x, mp[x][y][z], z);
}
int main() {
  int i, j, k, x, y;
  int tx, ty;
  while (~scanf("%d%d%d", &n, &m, &k)) {
    for (i = 0; i < n + 1; i++)
      for (j = 0; j < m + 1; j++) mp[i][j][0] = mp[i][j][1] = j;
    for (i = 0; i < k; i++) {
      scanf("%d%d", &x, &y);
      ;
      int b_x, b_y, ma = 2000000000;
      for (j = 0;; j++) {
        if (x - j > 0) {
          tx = x - j;
          ty = find(tx, y, 0);
          if (ty && ty != m + 1) {
            if (abs(ty - y) + j < ma)
              ma = abs(ty - y) + j, b_x = tx, b_y = ty;
            else if ((abs(ty - y) + j) == ma && tx < b_x)
              b_x = tx, b_y = ty;
          }
          mp[tx][ty][0] = ty;
          ty = find(tx, y, 1);
          if (ty && ty != m + 1) {
            if (abs(ty - y) + j < ma)
              ma = abs(ty - y) + j, b_x = tx, b_y = ty;
            else if ((abs(ty - y) + j) == ma && tx < b_x)
              b_x = tx, b_y = ty;
          }
          mp[tx][ty][1] = ty;
        }
        if (x + j <= n) {
          tx = x + j;
          ty = find(tx, y, 0);
          if (ty && ty != m + 1) {
            if (abs(ty - y) + j < ma)
              ma = abs(ty - y) + j, b_x = tx, b_y = ty;
            else if ((abs(ty - y) + j) == ma && tx < b_x)
              b_x = tx, b_y = ty;
          }
          mp[tx][ty][0] = ty;
          ty = find(tx, y, 1);
          if (ty && ty != m + 1) {
            if (abs(ty - y) + j < ma)
              ma = abs(ty - y) + j, b_x = tx, b_y = ty;
            else if ((abs(ty - y) + j) == ma && tx < b_x)
              b_x = tx, b_y = ty;
          }
          mp[tx][ty][1] = ty;
        }
        if (j + 1 > ma) break;
      }
      mp[b_x][b_y][0]--;
      mp[b_x][b_y][1]++;
      printf("%d %d\n", b_x, b_y);
    }
  }
  return 0;
}
