#include <bits/stdc++.h>
#pragma GCC optimize(0)
using namespace std;
const int INF = 1 << 30;
const int MAXBUF = 1 << 12;
char buf[MAXBUF], *ps = buf, *pe = buf + 1;
inline void rnext() {
  if (++ps == pe)
    pe = (ps = buf) +
         fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin);
}
template <class T>
inline bool in(T &ans) {
  ans = 0;
  T f = 1;
  if (ps == pe) return false;
  do {
    rnext();
    if ('-' == *ps) f = -1;
  } while (!isdigit(*ps) && ps != pe);
  if (ps == pe) return false;
  do {
    ans = ans * 10 + *ps - 48;
    rnext();
  } while (isdigit(*ps) && ps != pe);
  ans *= f;
  return true;
}
const int MAXOUT = 1 << 12;
char bufout[MAXOUT], outtmp[64] __attribute__((aligned(64))),
    *pout = bufout, *pend = bufout + MAXOUT;
inline void write() {
  fwrite(bufout, sizeof(char), pout - bufout, stdout);
  pout = bufout;
}
inline void out_char(char c) {
  *(pout++) = c;
  if (pout == pend) write();
}
inline void out_str(char *s) {
  while (*s) {
    *(pout++) = *(s++);
    if (pout == pend) write();
  }
}
inline void out_int(unsigned int x) {
  if (!x) {
    out_char('0');
    return;
  }
  if (x < 0) x = -x, out_char('-');
  char *len = outtmp;
  while (x) {
    *(len++) = x % 10 + 48;
    x /= 10;
  }
  *len = 0;
  for (char *i = outtmp, *j = len - 1; i < j; i++, j--) swap(*i, *j);
  out_str(outtmp);
}
int pa1[2003][2003], tmpppp[3], pa2[2003][2003];
int find(int *a, int v) { return (a[v] == v) ? v : a[v] = find(a, a[v]); }
inline void merge1(int *a, int v, int u) {
  v = find(a, v);
  u = find(a, u);
  a[u] = v;
}
int main() {
  int N, M, k;
  in(N);
  in(M);
  in(k);
  if (N < M) {
    const int n = N, m = M;
    int *pos1, *pos2;
    for (register int i = 0; i <= n + 1; i++) {
      pos1 = pa1[i];
      pos2 = pa2[i];
      for (register int j = 0; j <= m + 1; j++) {
        *(pos1++) = j;
        *(pos2++) = j;
      }
    }
    while (k--) {
      int x, y;
      in(x);
      in(y);
      int res = INF, rx = -1, ry = -1, cnt, i;
      for (register int j = 0; (j + x <= n || x - j >= 1) && j <= res; ++j) {
        if (x - j >= 1) {
          i = x - j;
          int cnt1 = find(pa1[i], y);
          if (!cnt1) cnt1 = -INF;
          int cnt2 = find(pa2[i], y);
          if (cnt2 == m + 1) cnt2 = INF;
          cnt = ((y << 1) <= cnt1 + cnt2) ? cnt1 : cnt2;
          if (res > abs(y - cnt) + abs(i - x)) {
            rx = i;
            ry = cnt;
            res = abs(y - cnt) + abs(i - x);
          } else if (res == abs(y - cnt) + abs(i - x)) {
            if (i <= rx) {
              ry = (cnt < ry || i < rx) ? cnt : ry;
              rx = i;
            }
          }
        }
        if (x + j <= n) {
          i = x + j;
          int cnt1 = find(pa1[i], y);
          if (!cnt1) cnt1 = -INF;
          int cnt2 = find(pa2[i], y);
          if (cnt2 == m + 1) cnt2 = INF;
          cnt = ((y << 1) <= cnt1 + cnt2) ? cnt1 : cnt2;
          if (res > abs(y - cnt) + abs(i - x)) {
            rx = i;
            ry = cnt;
            res = abs(y - cnt) + abs(i - x);
          } else if (res == abs(y - cnt) + abs(i - x)) {
            if (i <= rx) {
              ry = (cnt < ry || i < rx) ? cnt : ry;
              rx = i;
            }
          }
        }
      }
      merge1(pa1[rx], ry - 1, ry);
      merge1(pa2[rx], ry + 1, ry);
      out_int(rx);
      out_char(' ');
      out_int(ry);
      out_char('\n');
    }
  } else {
    const int n = M, m = N;
    int *pos1, *pos2;
    for (register int i = 0; i <= n + 1; i++) {
      pos1 = pa1[i];
      pos2 = pa2[i];
      for (register int j = 0; j <= m + 1; j++) {
        *(pos1++) = j;
        *(pos2++) = j;
      }
    }
    while (k--) {
      int x, y;
      in(x);
      in(y);
      swap(x, y);
      int res = INF, rx = -1, ry = -1, cnt, i;
      for (register int j = 0; (j + x <= n || x - j >= 1) && j <= res; ++j) {
        if (x - j >= 1) {
          i = x - j;
          int cnt1 = find(pa1[i], y);
          if (!cnt1) cnt1 = -INF;
          int cnt2 = find(pa2[i], y);
          if (cnt2 == m + 1) cnt2 = INF;
          cnt = ((y << 1) <= cnt1 + cnt2) ? cnt1 : cnt2;
          if (res > abs(y - cnt) + abs(i - x)) {
            rx = i;
            ry = cnt;
            res = abs(y - cnt) + abs(i - x);
          } else if (res == abs(y - cnt) + abs(i - x)) {
            if (ry >= cnt) {
              rx = (i < rx || ry > cnt) ? i : rx;
              ry = cnt;
            }
          }
        }
        if (x + j <= n) {
          i = x + j;
          int cnt1 = find(pa1[i], y);
          if (!cnt1) cnt1 = -INF;
          int cnt2 = find(pa2[i], y);
          if (cnt2 == m + 1) cnt2 = INF;
          cnt = ((y << 1) <= cnt1 + cnt2) ? cnt1 : cnt2;
          if (res > abs(y - cnt) + abs(i - x)) {
            rx = i;
            ry = cnt;
            res = abs(y - cnt) + abs(i - x);
          } else if (res == abs(y - cnt) + abs(i - x)) {
            if (ry >= cnt) {
              rx = (i < rx || ry > cnt) ? i : rx;
              ry = cnt;
            }
          }
        }
      }
      merge1(pa1[rx], ry - 1, ry);
      merge1(pa2[rx], ry + 1, ry);
      out_int((unsigned int)ry);
      out_char(' ');
      out_int((unsigned int)rx);
      out_char('\n');
    }
  }
  write();
}
