#include <bits/stdc++.h>
using namespace std;
int l[2100][2100], r[2100][2100];
bool a[2100][2100];
int n, m, k, ans;
pair<int, int> seat;
int xi, yi;
void check(int x, int y) {
  if (y < 0 || y >= m) return;
  int dist = abs(x - xi) + abs(y - yi);
  if (dist < ans) {
    ans = dist;
    seat = make_pair(x, y);
  } else {
    if (dist == ans) {
      seat = min(seat, make_pair(x, y));
    };
  };
};
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      a[i][j] = 0;
      l[i][j] = j;
      r[i][j] = j;
    };
  };
  for (int i = 0; i < k; ++i) {
    scanf("%d%d", &xi, &yi);
    xi--;
    yi--;
    ans = n + m + 2000;
    for (int d = 0; d <= ans; ++d) {
      int dist, xd, yd;
      if (xi - d >= 0) {
        check(xi - d, l[xi - d][yi]);
        check(xi - d, r[xi - d][yi]);
      };
      if (xi + d < n) {
        check(xi + d, l[xi + d][yi]);
        check(xi + d, r[xi + d][yi]);
      };
    };
    xi = seat.first;
    yi = seat.second;
    printf("%d %d\n", xi + 1, yi + 1);
    a[xi][yi] = true;
    l[xi][yi] = yi != 0 ? l[xi][yi - 1] : -10000;
    for (int i1 = yi + 1; i1 < m && a[xi][i1]; ++i1) {
      l[xi][i1] = l[xi][i1 - 1];
    };
    r[xi][yi] = yi != m - 1 ? r[xi][yi + 1] : 100000;
    for (int i1 = yi - 1; i1 >= 0 && a[xi][i1]; --i1) {
      r[xi][i1] = r[xi][i1 + 1];
    };
  };
  return 0;
};
