#include <bits/stdc++.h>
using namespace std;
const int N = 2005, INF = 2e9;
int n, m, k, p[N][N], rnk[N][N], le[N][N], ri[N][N];
bool used[N][N], iswap;
pair<int, pair<int, int> > ans;
int dsu_get(int x, int y) {
  return p[x][y] == y ? y : p[x][y] = dsu_get(x, p[x][y]);
}
inline void dsu_unite(int x, int y1, int y2) {
  int px = dsu_get(x, y1), py = dsu_get(x, y2);
  if (px != py) {
    if (rnk[x][px] < rnk[x][py]) {
      swap(px, py);
    }
    if (rnk[x][px] == rnk[x][py]) {
      rnk[x][px]++;
    }
    p[x][py] = px;
    le[x][px] = min(le[x][px], le[x][py]);
    ri[x][px] = max(ri[x][px], ri[x][py]);
  }
}
inline void upd(pair<int, pair<int, int> > val) {
  if (iswap) {
    if (val.first < ans.first) {
      ans = val;
    } else if (val.first == ans.first) {
      auto it1 = ans.second, it2 = val.second;
      swap(it1.first, it1.second);
      swap(it2.first, it2.second);
      if (it1 > it2) {
        ans = val;
      }
    }
  } else {
    ans = min(ans, val);
  }
}
inline pair<int, int> getans(int x, int y) {
  ans = make_pair(INF, make_pair(-1, -1));
  for (int i = 0; i <= ans.first; i++) {
    if (x - i >= 1) {
      int py = dsu_get(x - i, y);
      int ll = le[x - i][py], rr = ri[x - i][py];
      if (used[x - i][ll]) {
        ll--;
      }
      if (used[x - i][rr]) {
        rr++;
      }
      if (ll >= 1) {
        upd(make_pair(i + y - ll, make_pair(x - i, ll)));
      }
      if (rr <= m) {
        upd(make_pair(i + rr - y, make_pair(x - i, rr)));
      }
    }
    if (x + i <= n) {
      int py = dsu_get(x + i, y);
      int ll = le[x + i][py], rr = ri[x + i][py];
      if (used[x + i][ll]) {
        ll--;
      }
      if (used[x + i][rr]) {
        rr++;
      }
      if (ll >= 1) {
        upd(make_pair(i + y - ll, make_pair(x + i, ll)));
      }
      if (rr <= m) {
        upd(make_pair(i + rr - y, make_pair(x + i, rr)));
      }
    }
  }
  return ans.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  if (n > m) {
    iswap = true;
    swap(n, m);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      le[i][j] = ri[i][j] = p[i][j] = j;
    }
  }
  while (k--) {
    int x, y;
    cin >> x >> y;
    if (iswap) {
      swap(x, y);
    }
    auto it = getans(x, y);
    used[it.first][it.second] = true;
    if (it.second - 1 >= 1 && used[it.first][it.second - 1]) {
      dsu_unite(it.first, it.second - 1, it.second);
    }
    if (it.second + 1 <= m && used[it.first][it.second + 1]) {
      dsu_unite(it.first, it.second, it.second + 1);
    }
    if (iswap) {
      swap(it.first, it.second);
    }
    cout << it.first << " " << it.second << "\n";
  }
}
