#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int main() {
  int n, m;
  cin >> n >> m;
  ;
  int x, y, z, p;
  cin >> x >> y >> z >> p;
  ;
  x %= 4;
  y %= 2;
  z %= 4;
  for (int i = 0; i < int(p); ++i) {
    int mx = m, nx = n;
    int xk, yk;
    cin >> xk >> yk;
    ;
    for (int i = 0; i < int(x); ++i) {
      swap(mx, nx);
      int tmp = yk;
      yk = mx - xk + 1;
      xk = tmp;
    }
    if (y) {
      yk = mx - yk + 1;
    }
    for (int i = 0; i < int(z); ++i) {
      swap(mx, nx);
      int tmp = xk;
      xk = nx - yk + 1;
      yk = tmp;
    }
    cout << xk << " " << yk << endl;
  }
  return 0;
}
