#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
  long long t = 1;
  for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
  return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class edge>
struct Graph {
  vector<vector<edge>> adj;
  Graph(int n) {
    adj.clear();
    adj.resize(n + 5);
  }
  Graph() { adj.clear(); }
  void resize(int n) { adj.resize(n + 5); }
  void add(int s, edge e) { adj[s].push_back(e); }
  void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }
  int deg(int v) { return adj[v].size(); }
  vector<edge> &operator[](int t) { return adj[t]; }
};
const int maxn = 2200, maxbit = maxn * 2;
struct disjoint_set {
  vector<int> f;
  int find(int t) { return f[t] != -1 ? f[t] = find(f[t]) : t; }
  void unite(int s, int t) {
    int x = find(s), y = find(t);
    if (x != y) f[x] = y;
  }
};
int n, m;
disjoint_set U[maxn], D[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  int K, x, y;
  bool swaped = false;
  cin >> n >> m >> K;
  if (n > m) swap(n, m), swaped = true;
  for (int i = 1; i <= n; ++i) {
    U[i].f.resize(m + 2), fill((U[i].f).begin(), (U[i].f).end(), -1);
    D[i].f.resize(m + 2), fill((D[i].f).begin(), (D[i].f).end(), -1);
  }
  for (int Z = 1; Z <= K; ++Z) {
    cin >> x >> y;
    if (swaped) swap(x, y);
    pair<int, pair<int, int>> ans = make_pair(0x3F3F3F3F, make_pair(0, 0));
    auto update = [&x, &y, &ans, &swaped](int wx, int wy) {
      if (wy < 1 || wy > m) return;
      if (swaped)
        chkmin(ans, make_pair(abs(wx - x) + abs(wy - y), make_pair(wy, wx)));
      else
        chkmin(ans, make_pair(abs(wx - x) + abs(wy - y), make_pair(wx, wy)));
    };
    int i = 0;
    for (i = 0; i <= ans.first; ++i) {
      bool b = true;
      if (x + i <= n)
        update(x + i, U[x + i].find(y)), update(x + i, D[x + i].find(y)),
            b = false;
      if (x - i >= 1)
        update(x - i, U[x - i].find(y)), update(x - i, D[x - i].find(y)),
            b = false;
      if (b) break;
    }
    x = ans.second.first, y = ans.second.second;
    cout << x << " " << y << endl;
    if (swaped) swap(x, y);
    U[x].unite(y, y + 1), D[x].unite(y, y - 1);
  }
  return 0;
}
