#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma comment(linker, "/STACK:16000000")
using namespace std;
namespace Geometry {
struct point {
  double x;
  double y;
  void print() { printf("Point:x:%.8lf,y:%.8lf", x, y); }
};
struct line {
  double x;
  double c;
  void print() { printf("Line:x:%.8lf,c:%.8lf\n", x, c); }
};
line make_line(point a, point b) {
  double x = (a.x - b.x) / (a.y - b.y);
  double c = a.y - (a.x) * (x);
  return (line){x, c};
}
}  // namespace Geometry
namespace fast_IO {
const int IN_LEN = 10000000, OUT_LEN = 10000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf;
char *lastin = ibuf + IN_LEN;
const char *lastout = ibuf + OUT_LEN - 1;
inline char getchar_() {
  if (ih == lastin) lastin = ibuf + fread(ibuf, 1, IN_LEN, stdin), ih = ibuf;
  return (*ih++);
}
inline void putchar_(const char x) {
  if (ih == lastout) fwrite(obuf, 1, oh - obuf, stdout), oh = obuf;
  *oh++ = x;
}
inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }
}  // namespace fast_IO
using namespace fast_IO;
template <typename T>
inline void read(T &x) {
  char cu = getchar_();
  x = 0;
  bool fla = 0;
  while (!isdigit(cu)) {
    if (cu == '-') fla = 1;
    cu = getchar_();
  }
  while (isdigit(cu)) x = x * 10 + cu - '0', cu = getchar_();
  if (fla) x = -x;
}
template <typename T>
void printe(const T x) {
  if (x >= 10) printe(x / 10);
  putchar_((x % 10 + '0'));
}
template <typename T>
inline void print(const T x) {
  if (x < 0)
    putchar_(('-')), printe(-x);
  else
    printe(x);
}
using namespace Geometry;
const int inf = 0x3f3f3f3f;
const long long inf2 = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
int n, m;
int a[2005][2005], to[2005][2005];
int f1[4010000], f2[4010000];
int ansx, ansy;
void change(int x, int y, int d, int i) {
  int xx = i / (m + 2), yy = i % (m + 2);
  if (xx > 0 && xx <= n && yy > 0 && yy <= m &&
      abs(xx - x) + abs(yy - y) <= d) {
    if (ansx == -1 || xx < ansx || (xx == ansx && yy < ansy))
      ansx = xx, ansy = yy;
  }
}
int find1(int x) {
  if (x == f1[x]) return x;
  f1[x] = find1(f1[x]);
  return f1[x];
}
int find2(int x) {
  if (x == f2[x]) return x;
  f2[x] = find2(f2[x]);
  return f2[x];
}
bool check(int x, int y, int d) {
  int xx, yy;
  ansx = ansy = -1;
  xx = max(1, x - d);
  yy = x - xx + y - d;
  if (yy > 0) change(x, y, d, find1(to[xx][yy]));
  xx = max(1, x - d);
  yy = d - x + xx + y;
  if (yy <= m) change(x, y, d, find2(to[xx][yy]));
  if (ansx > 0) {
    printe(ansx);
    putchar_((' '));
    print(ansy);
    putchar_(('\n'));
    f1[to[ansx][ansy]] = to[ansx + 1][ansy - 1];
    f2[to[ansx][ansy]] = to[ansx + 1][ansy + 1];
    return 1;
  }
  yy = max(y - d, 1);
  xx = d + x - y + yy;
  if (xx <= n) change(x, y, d, find2(to[xx][yy]));
  yy = min(y + d, m);
  xx = d + x - yy + y;
  if (xx <= n) change(x, y, d, find1(to[xx][yy]));
  if (ansx > 0) {
    printe(ansx);
    putchar_((' '));
    print(ansy);
    putchar_(('\n'));
    f1[to[ansx][ansy]] = to[ansx + 1][ansy - 1];
    f2[to[ansx][ansy]] = to[ansx + 1][ansy + 1];
    return 1;
  }
  return 0;
}
int main() {
  read(n);
  read(m);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) {
      to[i][j] = i * (m + 2) + j;
      f1[i * (m + 2) + j] = f2[i * (m + 2) + j] = i * (m + 2) + j;
    }
  int q;
  read(q);
  while (q--) {
    int d = -inf;
    int x, y;
    read(x);
    read(y);
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        d = max(d, a[x + i][y + j] - abs(i) - abs(j));
    while (!check(x, y, d)) ++d;
    a[x][y] = d;
  }
  return flush(), 0;
}
