#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1677721600")
using namespace std;
const int MAXN = 2000 + 10;
const int MAXM = 1100000;
const double eps = 1e-12;
long long MOD = 1000000007;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
int fa[2][MAXN][MAXN];
int ret;
char ch;
int read() {
  ret = 0;
  while ((ch = getchar()) && isdigit(ch)) ret = ret * 10 + ch - '0';
  return ret;
}
void init(int n, int m) {
  memset(fa, 0, sizeof(fa));
  for (int p = 0; p <= 1; p++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        fa[p][i][j] = j;
      }
}
int find_fa(int id, int x, int y) {
  if (!fa[id][x][y]) return 0;
  return fa[id][x][y] == y ? y : fa[id][x][y] = find_fa(id, x, fa[id][x][y]);
}
bool inside(int x, int n) { return x >= 1 && x <= n; }
int n, m, k, r;
int x, y, ans_x, ans_y, dis;
void update(int new_dis, int nx, int ny) {
  if (new_dis < dis) {
    dis = new_dis;
    ans_x = nx;
    ans_y = ny;
  } else if (new_dis == dis) {
    if (!r) {
      if (nx < ans_x) {
        ans_x = nx;
        ans_y = ny;
      } else if (nx == ans_x)
        ans_y = min(ans_y, ny);
    } else {
      if (ny < ans_y) {
        ans_x = nx;
        ans_y = ny;
      } else if (ny == ans_y)
        ans_x = min(ans_x, nx);
    }
  }
}
int main() {
  n = read();
  m = read();
  k = read();
  r = n > m;
  if (n > m) swap(n, m);
  init(n, m);
  while (k--) {
    x = read();
    y = read();
    if (r) swap(x, y);
    ans_x = 1, ans_y = 1, dis = 0x3f3f3f3f;
    for (int dt = -1; dt <= 1; dt += 2) {
      for (int i = 0; i <= n; i++)
        if (dis >= i && inside(x + i * dt, n)) {
          int nx = x + dt * i;
          int pre_y = find_fa(0, nx, y), suf_y = find_fa(1, nx, y);
          int dis_pre = i + y - pre_y, dis_suf = i + suf_y - y;
          if (suf_y) {
            update(dis_suf, nx, suf_y);
          }
          if (pre_y) {
            update(dis_pre, nx, pre_y);
          }
        }
    }
    if (!r)
      printf("%d %d\n", ans_x, ans_y);
    else
      printf("%d %d\n", ans_y, ans_x);
    fa[0][ans_x][ans_y] = fa[0][ans_x][ans_y - 1];
    fa[1][ans_x][ans_y] = fa[1][ans_x][ans_y + 1];
  }
  return 0;
}
