#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
  a += b;
  if (a >= mod) a -= mod;
}
template <class T, class S>
inline void sub(T& a, S b) {
  a -= b;
  if (a < 0) a += mod;
}
template <class T, class S>
inline bool chkmax(T& a, S b) {
  return a < b ? a = b, true : false;
}
template <class T, class S>
inline bool chkmin(T& a, S b) {
  return a > b ? a = b, true : false;
}
struct DSU {
  int fa[N], L[N], R[N];
  bool used[N];
  void init() {
    for (int i = 0; i < N; i++) {
      fa[i] = i;
      L[i] = i;
      R[i] = i;
    }
  }
  int getRoot(int x) { return fa[x] == x ? x : fa[x] = getRoot(fa[x]); }
  void Merge(int u, int v) {
    int x = getRoot(u);
    int y = getRoot(v);
    chkmin(L[x], L[y]);
    chkmax(R[x], R[y]);
    fa[y] = x;
  }
} dsu[N];
int n, m, k;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n <= m) {
    for (int i = 1; i <= n; i++) dsu[i].init();
    while (k--) {
      pair<int, pair<int, int> > ans = make_pair(inf, make_pair(inf, inf));
      int x, y;
      scanf("%d%d", &x, &y);
      for (int g = 0; g <= ans.first; g++) {
        if (x + g <= n) {
          if (!dsu[x + g].used[y]) {
            chkmin(ans, make_pair(g, make_pair(x + g, y)));
          } else {
            int Rt = dsu[x + g].getRoot(y);
            pair<int, pair<int, int> > retL =
                make_pair(inf, make_pair(inf, inf));
            pair<int, pair<int, int> > retR =
                make_pair(inf, make_pair(inf, inf));
            if (dsu[x + g].L[Rt] - 1 > 0)
              retL = make_pair(g + y - dsu[x + g].L[Rt] + 1,
                               make_pair(x + g, dsu[x + g].L[Rt] - 1));
            if (dsu[x + g].R[Rt] + 1 <= m)
              retR = make_pair(g + dsu[x + g].R[Rt] + 1 - y,
                               make_pair(x + g, dsu[x + g].R[Rt] + 1));
            chkmin(ans, retL);
            chkmin(ans, retR);
          }
        }
        if (x - g >= 1) {
          if (!dsu[x - g].used[y]) {
            chkmin(ans, make_pair(g, make_pair(x - g, y)));
          } else {
            int Rt = dsu[x - g].getRoot(y);
            pair<int, pair<int, int> > retL =
                make_pair(inf, make_pair(inf, inf));
            pair<int, pair<int, int> > retR =
                make_pair(inf, make_pair(inf, inf));
            if (dsu[x - g].L[Rt] - 1 > 0)
              retL = make_pair(g + y - dsu[x - g].L[Rt] + 1,
                               make_pair(x - g, dsu[x - g].L[Rt] - 1));
            if (dsu[x - g].R[Rt] + 1 <= m)
              retR = make_pair(g + dsu[x - g].R[Rt] + 1 - y,
                               make_pair(x - g, dsu[x - g].R[Rt] + 1));
            chkmin(ans, retL);
            chkmin(ans, retR);
          }
        }
      }
      if (dsu[ans.second.first].used[ans.second.second - 1])
        dsu[ans.second.first].Merge(ans.second.second, ans.second.second - 1);
      if (dsu[ans.second.first].used[ans.second.second + 1])
        dsu[ans.second.first].Merge(ans.second.second, ans.second.second + 1);
      dsu[ans.second.first].used[ans.second.second] = true;
      printf("%d %d\n", ans.second.first, ans.second.second);
    }
  } else {
    for (int i = 1; i <= m; i++) dsu[i].init();
    while (k--) {
      pair<int, pair<int, int> > ans = make_pair(inf, make_pair(inf, inf));
      int x, y;
      scanf("%d%d", &x, &y);
      for (int g = 0; g <= ans.first; g++) {
        if (y + g <= m) {
          if (!dsu[y + g].used[x]) {
            chkmin(ans, make_pair(g, make_pair(x, y + g)));
          } else {
            int Rt = dsu[y + g].getRoot(x);
            pair<int, pair<int, int> > retL =
                make_pair(inf, make_pair(inf, inf));
            pair<int, pair<int, int> > retR =
                make_pair(inf, make_pair(inf, inf));
            if (dsu[y + g].L[Rt] - 1 > 0)
              retL = make_pair(g + x - dsu[y + g].L[Rt] + 1,
                               make_pair(dsu[y + g].L[Rt] - 1, y + g));
            if (dsu[y + g].R[Rt] + 1 <= n)
              retR = make_pair(g + dsu[y + g].R[Rt] + 1 - x,
                               make_pair(dsu[y + g].R[Rt] + 1, y + g));
            chkmin(ans, retL);
            chkmin(ans, retR);
          }
        }
        if (y - g >= 1) {
          if (!dsu[y - g].used[x]) {
            chkmin(ans, make_pair(g, make_pair(x, y - g)));
          } else {
            int Rt = dsu[y - g].getRoot(x);
            pair<int, pair<int, int> > retL =
                make_pair(inf, make_pair(inf, inf));
            pair<int, pair<int, int> > retR =
                make_pair(inf, make_pair(inf, inf));
            if (dsu[y - g].L[Rt] - 1 > 0)
              retL = make_pair(g + x - dsu[y - g].L[Rt] + 1,
                               make_pair(dsu[y - g].L[Rt] - 1, y - g));
            if (dsu[y - g].R[Rt] + 1 <= n)
              retR = make_pair(g + dsu[y - g].R[Rt] + 1 - x,
                               make_pair(dsu[y - g].R[Rt] + 1, y - g));
            chkmin(ans, retL);
            chkmin(ans, retR);
          }
        }
      }
      if (dsu[ans.second.second].used[ans.second.first - 1])
        dsu[ans.second.second].Merge(ans.second.first, ans.second.first - 1);
      if (dsu[ans.second.second].used[ans.second.first + 1])
        dsu[ans.second.second].Merge(ans.second.first, ans.second.first + 1);
      dsu[ans.second.second].used[ans.second.first] = true;
      printf("%d %d\n", ans.second.first, ans.second.second);
    }
  }
  return 0;
}
