#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 1 << 30 - 1;
const long long i64_inf = 1ll << 63 - 1;
const double pi = acos(-1.0);
using namespace std;
struct DSU {
  int par[2001];
  int sz[2001];
  int Fuck[2001];
  int FuckFuck[2001];
  DSU(int n = 0) {
    for (int i = 0; i < (int)n; i++)
      sz[i] = 1, Fuck[i] = FuckFuck[i] = par[i] = i;
  };
  int get_set(int x) { return (par[x] == x) ? x : par[x] = get_set(par[x]); }
  void union_set(int x, int y) {
    x = get_set(x);
    y = get_set(y);
    if (x == y) return;
    if (sz[x] > sz[y]) swap(x, y);
    par[x] = y;
    Fuck[y] = min(Fuck[y], Fuck[x]);
    FuckFuck[y] = max(FuckFuck[y], FuckFuck[x]);
  }
};
int n, m, k;
bool used[2000][2000];
DSU a[2000];
bool FuckFuckFuck;
void print() {
  printf("--------------------------------\n");
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)m; j++) printf("%d ", used[i][j]);
    puts("");
  }
  puts("\n");
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)m; j++) printf("%d ", a[i].get_set(j));
    puts("");
  }
  printf("--------------------------------\n\n\n\n");
}
void upd(int x, int y, int newx, int newy, int& resx, int& resy) {
  if (newx < 0 || newx >= n || used[newx][newy]) return;
  int newd = abs(x - newx) + abs(y - newy);
  int oldd = abs(x - resx) + abs(y - resy);
  if (newd < oldd) {
    resx = newx;
    resy = newy;
  }
  if (newd != oldd) return;
  if (!FuckFuckFuck) {
    if (newx < resx) {
      resx = newx;
      resy = newy;
    }
    if (newx != resx) return;
    if (newy < resy) {
      resx = newx;
      resy = newy;
    }
    return;
  }
  if (newy < resy) {
    resx = newx;
    resy = newy;
  }
  if (newy != resy) return;
  if (newx < resx) {
    resx = newx;
    resy = newy;
  }
}
pair<int, int> go(int x, int y) {
  int resx = int_inf;
  int resy = int_inf;
  int maxd = max(n - x, x);
  for (int d = 0; d <= maxd; d++) {
    int newx = x + d;
    if (newx - x > abs(resx - x) + abs(resy - y)) break;
    upd(x, y, newx, y, resx, resy);
    if (newx >= 0 && newx < n && used[newx][y] &&
        a[newx].Fuck[a[newx].get_set(y)] != 0)
      upd(x, y, newx, a[newx].Fuck[a[newx].get_set(y)] - 1, resx, resy);
    if (newx >= 0 && newx < n && used[newx][y] &&
        a[newx].FuckFuck[a[newx].get_set(y)] != m - 1)
      upd(x, y, newx, a[newx].FuckFuck[a[newx].get_set(y)] + 1, resx, resy);
    newx = x - d;
    if (x - newx > abs(resx - x) + abs(resy - y)) break;
    upd(x, y, newx, y, resx, resy);
    if (newx >= 0 && newx < n && used[newx][y] &&
        a[newx].Fuck[a[newx].get_set(y)] != 0)
      upd(x, y, newx, a[newx].Fuck[a[newx].get_set(y)] - 1, resx, resy);
    if (newx >= 0 && newx < n && used[newx][y] &&
        a[newx].FuckFuck[a[newx].get_set(y)] != m - 1)
      upd(x, y, newx, a[newx].FuckFuck[a[newx].get_set(y)] + 1, resx, resy);
  }
  assert(resx != int_inf && resy != int_inf);
  used[resx][resy] = 1;
  if (resy != m - 1 && used[resx][resy + 1]) a[resx].union_set(resy, resy + 1);
  if (resy != 0 && used[resx][resy - 1]) a[resx].union_set(resy, resy - 1);
  return make_pair(resx, resy);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(used, 0, sizeof used);
  FuckFuckFuck = (n > m);
  if (FuckFuckFuck) swap(n, m);
  for (int i = 0; i < (int)n; i++) a[i] = DSU(m);
  for (int i = 0; i < (int)k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    if (FuckFuckFuck) swap(x, y);
    pair<int, int> r = go(x, y);
    if (FuckFuckFuck) swap(r.first, r.second);
    printf("%d %d\n", r.first + 1, r.second + 1);
  }
  return 0;
}
