#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p, i, j;
  cin >> n >> m >> x >> y >> z >> p;
  int _n = n, _m = m;
  for (i = 0; i < p; i++) {
    n = _n;
    m = _m;
    int ans_x, ans_y, _x, _y;
    scanf("%d", &ans_x);
    scanf("%d", &ans_y);
    _x = ans_x, _y = ans_y;
    for (j = 0; j < x % 4; j++) {
      ans_y = n - _x + 1;
      ans_x = _y;
      _x = ans_x;
      _y = ans_y;
      swap(n, m);
    }
    for (j = 0; j < y % 2; j++) {
      ans_y = m - _y + 1;
      _y = ans_y;
    }
    for (j = 0; j < z % 4; j++) {
      ans_y = _x;
      ans_x = m - _y + 1;
      _x = ans_x;
      _y = ans_y;
      swap(n, m);
    }
    printf("%d %d\n", ans_x, ans_y);
  }
  return 0;
}
