#include <bits/stdc++.h>
using namespace std;
const int maxn = 2111;
const int maxm = 2111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
int n, m;
int k;
int phx[] = {-1, 0, 0, 1, 1, 1, -1, -1};
int phy[] = {0, -1, 1, 0, -1, 1, 1, -1};
int mar[maxn][maxn];
int sakura[maxn][maxn];
bool solve(int a, int b, int k) {
  if (mar[a][b] == 0) {
    printf("%d %d", a, b);
    mar[a][b] = 1;
    return 0;
  }
  for (int i = -k; i <= k; ++i) {
    int j = -(k - abs(i));
    int x = a + i;
    int y = b + j;
    if (0 < x && x <= n)
      if (0 < y && y <= m)
        if (mar[x][y] == 0) {
          printf("%d %d", x, y);
          mar[x][y] = 1;
          sakura[a][b] = k;
          return 0;
        }
    j = (k - abs(i));
    x = a + i;
    y = b + j;
    if (0 < x && x <= n)
      if (0 < y && y <= m)
        if (mar[x][y] == 0) {
          printf("%d %d", x, y);
          mar[x][y] = 1;
          sakura[a][b] = k;
          return 0;
        }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    int d = sakura[a][b];
    for (int j = 0; j < 8; ++j)
      d = max(d, sakura[a + phx[j]][b + phy[j]] - 1 - (i > 3));
    while (solve(a, b, d)) ++d;
    printf("\n");
  }
}
