#include <bits/stdc++.h>
using namespace std;
int n, m, k, f, x, y;
int vis[2005][2005], bel[2005][2005], ber[2005][2005];
int Getbel(int i, int x) {
  if (!bel[i][x]) return x;
  return bel[i][x] = Getbel(i, bel[i][x]);
}
void Joinl(int i, int a, int b) {
  int p = Getbel(i, a), q = Getbel(i, b);
  bel[i][q] = p;
}
int Getber(int i, int x) {
  if (!ber[i][x]) return x;
  return ber[i][x] = Getber(i, ber[i][x]);
}
void Joinr(int i, int a, int b) {
  int p = Getber(i, a), q = Getber(i, b);
  ber[i][p] = q;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n > m) swap(n, m), f = 1;
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &x, &y);
    int ans = 0x3f3f3f3f, x0 = 0x3f3f3f3f, y0 = 0x3f3f3f3f;
    if (f) swap(x, y);
    if (!vis[x][y]) {
      vis[x][y] = 1;
      if (f) swap(x, y);
      printf("%d %d\n", x, y);
      continue;
    }
    for (int j = 0; j <= ans; j++) {
      if (x + j > n && x - j < 1) break;
      if (x + j <= n) {
        if (!vis[x + j][y]) {
          int now = j, nx = x + j, ny = y;
          if (now < ans)
            ans = now, x0 = nx, y0 = ny;
          else if (now == ans) {
            if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
            if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
          }
        } else {
          int a = Getbel(x + j, y) - 1;
          while (a > 0 && vis[x + j][a])
            Joinl(x + j, a, y), a = Getbel(x + j, a) - 1;
          if (a > 0) {
            int now = j + y - a, nx = x + j, ny = a;
            if (now < ans)
              ans = now, x0 = nx, y0 = ny;
            else if (now == ans) {
              if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
              if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
            }
          }
          int b = Getber(x + j, y) + 1;
          while (b <= m && vis[x + j][b])
            Joinr(x + j, y, b), b = Getber(x + j, b) + 1;
          if (b <= m) {
            int now = j + b - y, nx = x + j, ny = b;
            if (now < ans)
              ans = now, x0 = nx, y0 = ny;
            else if (now == ans) {
              if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
              if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
            }
          }
        }
      }
      if (x - j > 0) {
        if (!vis[x - j][y]) {
          int now = j, nx = x - j, ny = y;
          if (now < ans)
            ans = now, x0 = nx, y0 = ny;
          else if (now == ans) {
            if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
            if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
          }
        } else {
          int a = Getbel(x - j, y) - 1;
          while (a > 0 && vis[x - j][a])
            Joinl(x - j, a, y), a = Getbel(x - j, a) - 1;
          if (a > 0) {
            int now = j + y - a, nx = x - j, ny = a;
            if (now < ans)
              ans = now, x0 = nx, y0 = ny;
            else if (now == ans) {
              if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
              if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
            }
          }
          int b = Getber(x - j, y) + 1;
          while (b <= m && vis[x - j][b])
            Joinr(x - j, y, b), b = Getber(x - j, b) + 1;
          if (b <= m) {
            int now = j + b - y, nx = x - j, ny = b;
            if (now < ans)
              ans = now, x0 = nx, y0 = ny;
            else if (now == ans) {
              if (f && (ny < y0 || (ny == y0 && nx < x0))) x0 = nx, y0 = ny;
              if (!f && (nx < x0 || (nx == x0 && ny < y0))) x0 = nx, y0 = ny;
            }
          }
        }
      }
    }
    vis[x0][y0] = 1;
    if (f) swap(x0, y0);
    printf("%d %d\n", x0, y0);
  }
}
