#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long MAX = 2e3 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int nr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int nc[] = {0, 1, 0, -1, 1, -1, 1, -1};
int n, m, q, x, y, a, b, z[MAX][MAX];
bool vis[MAX][MAX];
bool inside(int r, int c) {
  if (r > 0 && r <= n && c > 0 && c <= m) return 1;
  return 0;
}
bool f(int r, int c, int k) {
  int le = max(1, r - k), ri = min(n, r + k);
  for (int i = le; i <= ri; i++) {
    int h = k - abs(r - i);
    if (c - h > 0 && !vis[i][c - h]) return x = i, y = c - h, 1;
    if (c + h <= m && !vis[i][c + h]) return x = i, y = c + h, 1;
  }
  return 0;
}
int main() {
  cout << fixed << setprecision(10);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> q;
  while (q--) {
    cin >> a >> b;
    for (int k = 0; k <= 7; k++) {
      if (!inside(a + nr[k], b + nc[k])) continue;
      z[a][b] = max(z[a][b], z[a + nr[k]][b + nc[k]] - abs(nr[k]) - abs(nc[k]));
    }
    while (!f(a, b, z[a][b])) z[a][b]++;
    cout << x << " " << y << "\n";
    vis[x][y] = 1;
  }
  return 0;
}
