#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int P[N][N][2];
int n, m, t, ex, ey;
int dis(int x, int y) { return abs(ex - x) + abs(ey - y); }
bool flag;
int find(int x, int y, int p) {
  return P[x][y][p] == y ? y : P[x][y][p] = find(x, P[x][y][p], p);
}
inline void chk(int &ans, int nx, int ny, int &x, int &y) {
  int d = dis(nx, ny);
  if (ans > d) {
    ans = d, x = nx, y = ny;
  } else if (ans == d) {
    if (!flag) {
      if (nx < x) {
        x = nx, y = ny;
      } else if (nx == x && ny < y) {
        x = nx, y = ny;
      }
    } else {
      if (ny < y) {
        x = nx, y = ny;
      } else if (ny == y && nx < x) {
        x = nx;
      }
    }
  }
}
inline void update(int r, int &ans, int &x, int &y) {
  int nx = r, ny = find(r, ey, 0);
  if (ny <= m) {
    chk(ans, nx, ny, x, y);
  }
  ny = find(r, ey, 1);
  if (ny > 0) {
    chk(ans, nx, ny, x, y);
  }
}
int main() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) P[i][j][0] = P[i][j][1] = j;
  scanf("%d%d%d", &n, &m, &t);
  flag = 0;
  int cnt = 0;
  if (n > m) {
    swap(n, m);
    flag = 1;
  }
  int test = 0;
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (flag) swap(x, y);
    ex = x, ey = y;
    int d = 0, ans = ~0u >> 2, nx, ny;
    while (d <= ans && d < n) {
      int r = x - d;
      if (r > 0 && r <= n) update(r, ans, nx, ny);
      r = x + d;
      if (r > 0 && r <= n) update(r, ans, nx, ny);
      d++;
    }
    P[nx][ny][0] = ny + 1;
    P[nx][ny][1] = ny - 1;
    if (flag) swap(nx, ny);
    printf("%d %d\n", nx, ny);
  }
}
