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