#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010, oo = ~0U >> 1;
int n, m, T;
int rev, ans, resx, resy;
int L[maxn][maxn], R[maxn][maxn];
int findl(int x, int y) {
  if (L[x][L[x][y]] == L[x][y]) return L[x][y];
  return L[x][y] == y ? y : (L[x][y] = findl(x, L[x][y]));
}
int findr(int x, int y) {
  if (R[x][R[x][y]] == R[x][y]) return R[x][y];
  if (R[x][R[x][R[x][y]]] == R[x][R[x][y]]) return R[x][R[x][y]];
  return R[x][y] == y ? y : (R[x][y] = findr(x, R[x][y]));
}
int cmp(int x1, int y1, int x2, int y2) {
  if (rev) swap(x1, y1), swap(x2, y2);
  return x1 < x2 || (x1 == x2 && (y1 < y2));
}
void updata(int x, int y, int Ox, int Oy) {
  if (y == 0 || y == m + 1) return;
  if (abs(x - Ox) + abs(y - Oy) < ans ||
      (abs(x - Ox) + abs(y - Oy) == ans && cmp(x, y, resx, resy)))
    ans = abs(x - Ox) + abs(y - Oy), resx = x, resy = y;
}
int main() {
  int i, j, x, y;
  scanf("%d %d %d\n", &n, &m, &T);
  if (n > m) swap(n, m), rev = true;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) L[i][j] = j, R[i][j] = j;
  while (T--) {
    scanf("%d %d\n", &x, &y);
    if (rev) swap(x, y);
    ans = oo;
    for (i = x; i <= n && i - x <= ans; ++i)
      updata(i, findl(i, y), x, y), updata(i, findr(i, y), x, y);
    for (i = x; i >= 1 && x - i <= ans; --i)
      updata(i, findl(i, y), x, y), updata(i, findr(i, y), x, y);
    L[resx][resy] = resy - 1;
    R[resx][resy] = resy + 1;
    if (rev) swap(resx, resy);
    printf("%d %d\n", resx, resy);
  }
  return 0;
}
