#include <bits/stdc++.h>
using namespace std;
const int maxN = 2005;
int l[maxN][maxN], r[maxN][maxN];
int n, m, k, flag, nx, ny, ax, ay, best;
void Init() {
  scanf("%d%d%d", &n, &m, &k);
  if (n > m) swap(n, m), flag = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= m + 1; ++j) l[i][j] = r[i][j] = j;
}
int q[maxN];
int find(int fa[], int x) {
  int t = 0;
  while (fa[x] != x) {
    q[++t] = x;
    x = fa[x];
  }
  for (int i = 1; i <= t; ++i) fa[q[i]] = x;
  return x;
}
void cmp(int x, int y) {
  int d = ((x - nx) > 0 ? (x - nx) : (-(x - nx))) +
          ((y - ny) > 0 ? (y - ny) : (-(y - ny)));
  if (d < best)
    ax = x, ay = y, best = d;
  else if (d == best) {
    if (!flag && (x < ax || (x == ax && y < ay))) ax = x, ay = y;
    if (flag && (y < ay || (y == ay && x < ax))) ax = x, ay = y;
  }
}
void Work() {
  int ky;
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &nx, &ny);
    if (flag) swap(nx, ny);
    best = 2147483647;
    for (int j = 0; j <= n; ++j) {
      if ((nx - j < 1 && nx + j > n) || j > best) break;
      if (nx - j >= 1) {
        ky = find(l[nx - j], ny);
        if (ky) cmp(nx - j, ky);
        ky = find(r[nx - j], ny);
        if (ky <= m) cmp(nx - j, ky);
      }
      if (nx + j <= n) {
        ky = find(l[nx + j], ny);
        if (ky) cmp(nx + j, ky);
        ky = find(r[nx + j], ny);
        if (ky <= m) cmp(nx + j, ky);
      }
    }
    l[ax][ay] = ay - 1;
    r[ax][ay] = ay + 1;
    if (flag) swap(ax, ay);
    printf("%d %d\n", ax, ay);
  }
}
int main() {
  Init();
  Work();
  return 0;
}
