#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
int n;
const int maxn = 2100;
struct bit {
  int l[maxn], r[maxn];
  int n;
  void init(int _n) {
    n = _n;
    for (int i = 0; i <= n + 1; i++) {
      l[i] = i;
      r[i] = i;
    }
  }
  void del(int z) {
    l[z] = z - 1;
    r[z] = z + 1;
  }
  int fl(int x) {
    if (x == l[x]) return x;
    return l[x] = fl(l[x]);
  }
  int fr(int x) {
    if (x == r[x]) return x;
    return r[x] = fr(r[x]);
  }
} bt[2011];
int sm[2011];
bool v[2011][2011];
int main() {
  int i, j, k;
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (i = 1; i <= n; i++) {
    bt[i].init(m);
    for (j = 1; j <= m; j++) v[i][j] = 1;
    sm[i] = m;
  }
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int ans = 111111111;
    int ax = 111111, ay = 111111, oc = 0;
    for (i = 0;; i++) {
      if (i > ans) break;
      int w;
      if (x - i >= 1) {
        if (v[x - i][y]) {
          w = y;
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x - i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x - i < ax) {
              ax = x - i;
              ay = w;
            } else if (x - i == ax) {
              ay = min(ay, w);
            }
          }
        }
        w = bt[x - i].fl(y);
        if (w > 0) {
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x - i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x - i < ax) {
              ax = x - i;
              ay = w;
            } else if (x - i == ax) {
              ay = min(ay, w);
            }
          }
        }
        w = bt[x - i].fr(y);
        if (w <= m) {
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x - i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x - i < ax) {
              ax = x - i;
              ay = w;
            } else if (x - i == ax) {
              ay = min(ay, w);
            }
          }
        }
      }
      if (x + i <= n) {
        if (v[x + i][y]) {
          w = y;
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x + i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x + i < ax) {
              ax = x + i;
              ay = w;
            } else if (x + i == ax) {
              ay = min(ay, w);
            }
          }
        }
        w = bt[x + i].fl(y);
        if (w > 0) {
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x + i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x + i < ax) {
              ax = x + i;
              ay = w;
            } else if (x + i == ax) {
              ay = min(ay, w);
            }
          }
        }
        w = bt[x + i].fr(y);
        if (w <= m) {
          if (ans > i + abs(y - w)) {
            ans = i + abs(y - w);
            ax = x + i;
            ay = w;
          } else if (ans == i + abs(y - w)) {
            if (x + i < ax) {
              ax = x + i;
              ay = w;
            } else if (x + i == ax) {
              ay = min(ay, w);
            }
          }
        }
      }
    }
    printf("%d %d\n", ax, ay);
    bt[ax].del(ay);
    --sm[ax];
    ++oc;
    v[ax][ay] = 0;
  }
  return 0;
}
