#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
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline int read() {
  int r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
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) { return x == f1[x] ? x : f1[x] = find1(f1[x]); }
int find2(int x) { return x == f2[x] ? x : f2[x] = find2(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) {
    printf("%d %d\n", ansx, ansy);
    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) {
    printf("%d %d\n", ansx, ansy);
    f1[to[ansx][ansy]] = to[ansx + 1][ansy - 1];
    f2[to[ansx][ansy]] = to[ansx + 1][ansy + 1];
    return 1;
  }
  return 0;
}
int main() {
  n = read();
  m = read();
  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();
  while (q--) {
    int d = -inf;
    int x = read(), y = read();
    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 0;
}
