#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  x = x % 4, y = y % 2, z = z % 4;
  while (p--) {
    int i, j, tmp, tn = n, tm = m;
    cin >> i >> j;
    for (int k = 0; k < x; k++) {
      tmp = i;
      i = j;
      j = tn + 1 - tmp;
      swap(tn, tm);
    }
    if (y) j = tm + 1 - j;
    for (int k = 0; k < z; k++) {
      tmp = i;
      i = tm + 1 - j;
      j = tmp;
      swap(tn, tm);
    }
    cout << i << " " << j << endl;
  }
  return 0;
}
