#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int h, w, k;
pair<int, int> query[100005];
int L[2005][2005], R[2005][2005];
int putted[2005][2005];
int y, x;
void renew(int y, int x, int& ay, int& ax, int y2, int x2) {
  int d1 = abs(ay - y) + abs(ax - x), d2 = abs(y - y2) + abs(x - x2);
  if (d1 > d2 || (d1 == d2 && make_pair(ay, ax) > make_pair(y2, x2))) {
    ay = y2;
    ax = x2;
  }
}
pair<int, int> findpos(int y, int x) {
  int ay = INF, ax = INF;
  for (int d = 0; d <= 2002; ++d) {
    if (abs(y - ay) + abs(x - ax) < d) break;
    int y2 = y - d, x2;
    if (y2 >= 0) {
      x2 = L[y2][x];
      if (x2 >= 0) renew(y, x, ay, ax, y2, x2);
      x2 = R[y2][x];
      if (x2 < w) renew(y, x, ay, ax, y2, x2);
    }
    y2 = y + d;
    if (y2 < h) {
      x2 = L[y2][x];
      if (x2 >= 0) renew(y, x, ay, ax, y2, x2);
      x2 = R[y2][x];
      if (x2 < w) renew(y, x, ay, ax, y2, x2);
    }
  }
  return make_pair(ay, ax);
}
void fill(int y, int x) {
  putted[y][x] = 1;
  L[y][x] = (x == 0 ? -1 : L[y][x - 1]);
  for (int i = x + 1; i < w; ++i) {
    if (!putted[y][i]) continue;
    L[y][i] = L[y][i - 1];
  }
  R[y][x] = (x == w - 1 ? INF : R[y][x + 1]);
  for (int i = x - 1; i >= 0; --i) {
    if (!putted[y][i]) continue;
    R[y][i] = R[y][i + 1];
  }
}
int main() {
  cin >> h >> w >> k;
  for (int i = 0; i < k; ++i) {
    cin >> query[i].first >> query[i].second;
    --query[i].first;
    --query[i].second;
  }
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) L[i][j] = R[i][j] = j;
  for (int i = 0; i < k; ++i) {
    pair<int, int> p = findpos(query[i].first, query[i].second);
    printf("%d %d\n", p.first + 1, p.second + 1);
    fill(p.first, p.second);
  }
  return 0;
}
