#include <bits/stdc++.h>
using namespace std;
struct point2i {
  int x, y;
};
int n, m, k;
bool rotated;
void ReadData() {
  scanf("%d %d %d", &n, &m, &k);
  rotated = false;
  if (n > m) {
    swap(n, m);
    rotated = true;
  }
}
int nextPos[2009][2009], prevPos[2009][2009];
void Init() {
  for (int i = 0; i < 2009; i++) {
    for (int j = 0; j < 2009; j++) {
      nextPos[i][j] = j;
      prevPos[i][j] = j;
    }
  }
}
int getRight(int row, int column) {
  if (column > m) {
    return -1;
  }
  nextPos[row][column] = nextPos[row][column] == column
                             ? column
                             : getRight(row, nextPos[row][column]);
  return nextPos[row][column];
}
int markRight(int row, int column) {
  if (column > m) {
    return -1;
  }
  nextPos[row][column] = nextPos[row][column] == column
                             ? nextPos[row][column] + 1
                             : markRight(row, nextPos[row][column]);
  return nextPos[row][column];
}
int getLeft(int row, int column) {
  if (column < 1) {
    return -1;
  }
  prevPos[row][column] = prevPos[row][column] == column
                             ? column
                             : getLeft(row, prevPos[row][column]);
  return prevPos[row][column];
}
int markLeft(int row, int column) {
  if (column < 1) {
    return -1;
  }
  prevPos[row][column] = prevPos[row][column] == column
                             ? prevPos[row][column] - 1
                             : markLeft(row, prevPos[row][column]);
  return prevPos[row][column];
}
void SolveRotated();
void Solve() {
  Init();
  if (rotated) {
    SolveRotated();
    return;
  }
  for (int T = 0; T < k; T++) {
    point2i p;
    scanf("%d %d", &p.y, &p.x);
    int bestResult = 5000;
    point2i answer, currentAnswer;
    answer.x = 3000;
    answer.y = 3000;
    for (int dy = 0; dy <= bestResult; dy++) {
      int left = -1, right = -1, dleft = 5000, dright = 5000,
          currentBestResult = 5000;
      currentAnswer.y = 3000;
      currentAnswer.x = 3000;
      if (p.y - dy >= 1) {
        left = getLeft(p.y - dy, p.x);
        right = getRight(p.y - dy, p.x);
        if (left != -1) {
          dleft = p.x - left;
        }
        if (right != -1) {
          dright = right - p.x;
        }
        int r = dy + min(dleft, dright);
        if (r <= currentBestResult) {
          currentAnswer.y = p.y - dy;
          currentAnswer.x = dleft <= dright ? left : right;
          currentBestResult = r;
        }
      }
      if (p.y + dy <= n) {
        left = getLeft(p.y + dy, p.x);
        right = getRight(p.y + dy, p.x);
        dleft = 5000;
        dright = 5000;
        if (left != -1) {
          dleft = p.x - left;
        }
        if (right != -1) {
          dright = right - p.x;
        }
        int r = dy + min(dleft, dright);
        if (r < currentBestResult) {
          currentAnswer.y = p.y + dy;
          currentAnswer.x = dleft <= dright ? left : right;
          currentBestResult = r;
        }
      }
      if ((currentBestResult < bestResult) ||
          (currentBestResult == bestResult &&
           (currentAnswer.y < answer.y ||
            (currentAnswer.y == answer.y && currentAnswer.x < answer.x)))) {
        answer = currentAnswer;
        bestResult = currentBestResult;
      }
    }
    if (answer.x <= p.x) {
      markLeft(answer.y, p.x);
      nextPos[answer.y][answer.x]++;
    } else {
      markRight(answer.y, p.x);
      prevPos[answer.y][answer.x]--;
    }
    printf("%d %d\n", answer.y, answer.x);
  }
}
void SolveRotated() {
  for (int T = 0; T < k; T++) {
    point2i p;
    scanf("%d %d", &p.x, &p.y);
    int bestResult = 5000;
    point2i answer, currentAnswer;
    answer.x = 3000;
    answer.y = 3000;
    for (int dy = 0; dy <= bestResult; dy++) {
      int left = -1, right = -1, dleft = 5000, dright = 5000,
          currentBestResult = 5000;
      currentAnswer.y = 3000;
      currentAnswer.x = 3000;
      if (p.y - dy >= 1) {
        left = getLeft(p.y - dy, p.x);
        right = getRight(p.y - dy, p.x);
        if (left != -1) {
          dleft = p.x - left;
        }
        if (right != -1) {
          dright = right - p.x;
        }
        int r = dy + min(dleft, dright);
        int x2 = dleft <= dright ? left : right;
        if ((r < currentBestResult) ||
            (r == currentBestResult && x2 < currentAnswer.x)) {
          currentAnswer.y = p.y - dy;
          currentAnswer.x = x2;
          currentBestResult = r;
        }
      }
      if (p.y + dy <= n) {
        left = getLeft(p.y + dy, p.x);
        right = getRight(p.y + dy, p.x);
        dleft = 5000;
        dright = 5000;
        if (left != -1) {
          dleft = p.x - left;
        }
        if (right != -1) {
          dright = right - p.x;
        }
        int r = dy + min(dleft, dright);
        int x2 = dleft <= dright ? left : right;
        if ((r < currentBestResult) ||
            (r == currentBestResult && x2 < currentAnswer.x)) {
          currentAnswer.y = p.y + dy;
          currentAnswer.x = x2;
          currentBestResult = r;
        }
      }
      if ((currentBestResult < bestResult) ||
          (currentBestResult == bestResult &&
           (currentAnswer.x < answer.x ||
            (currentAnswer.x == answer.x && currentAnswer.y < answer.y)))) {
        answer = currentAnswer;
        bestResult = currentBestResult;
      }
    }
    if (answer.x <= p.x) {
      markLeft(answer.y, p.x);
      nextPos[answer.y][answer.x]++;
    } else {
      markRight(answer.y, p.x);
      prevPos[answer.y][answer.x]--;
    }
    printf("%d %d\n", answer.x, answer.y);
  }
}
void WriteData() {}
int main() {
  int QWE = 1;
  for (int T = 0; T < QWE; T++) {
    ReadData();
    Solve();
    WriteData();
  }
  return 0;
}
