#include <bits/stdc++.h>
using namespace std;
int n, m, k, idx = 1, ans;
pair<int, int> s;
int x, y;
int leftt[2100][2100], rightt[2100][2100];
bool a[2100][2100];
void check(int x1, int y1) {
  if (y1 < 0 || y1 >= m) return;
  int d = abs(x1 - x) + abs(y1 - y);
  if (d < ans) {
    ans = d;
    s = make_pair(x1, y1);
  } else {
    if (d == ans) {
      s = min(s, make_pair(x1, y1));
    };
  };
};
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      leftt[i][j] = j;
      rightt[i][j] = j;
      a[i][j] = 0;
    };
  }
  for (int ii = 0; ii < k; ii++) {
    scanf("%d%d", &x, &y);
    x--, y--;
    ans = n + m + 2000;
    for (int d = 0; d <= ans; d++) {
      int dist;
      if (x - d >= 0) {
        check(x - d, leftt[x - d][y]), check(x - d, rightt[x - d][y]);
      };
      if (x + d < n) {
        check(x + d, leftt[x + d][y]), check(x + d, rightt[x + d][y]);
      };
    };
    x = s.first, y = s.second;
    printf("%d %d\n", x + 1, y + 1);
    a[x][y] = true;
    if (y != 0)
      leftt[x][y] = leftt[x][y - 1];
    else
      leftt[x][y] = -10000;
    for (int i1 = y + 1; i1 < m && a[x][i1]; i1++) {
      leftt[x][i1] = leftt[x][i1 - 1];
    };
    if (y != m - 1)
      rightt[x][y] = rightt[x][y + 1];
    else
      rightt[x][y] = 100000;
    for (int i1 = y - 1; i1 >= 0 && a[x][i1]; i1--) {
      rightt[x][i1] = rightt[x][i1 + 1];
    };
  };
  return 0;
};
