#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  int u, v, uu, vv, uuu, vvv;
  while (p--) {
    scanf("%d%d", &u, &v);
    if (x == 0) uu = u, vv = v;
    if (x == 1) uu = v, vv = n - u + 1;
    if (x == 2) uu = n - u + 1, vv = m - v + 1;
    if (x == 3) uu = m - v + 1, vv = u;
    if (y) {
      if (x % 2)
        vv = n + 1 - vv;
      else
        vv = m + 1 - vv;
    }
    int nn = n, mm = m;
    if (x % 2) swap(nn, mm);
    if (z == 0) uuu = uu, vvv = vv;
    if (z == 1) uuu = mm - vv + 1, vvv = uu;
    if (z == 2) uuu = nn - uu + 1, vvv = mm - vv + 1;
    if (z == 3) uuu = vv, vvv = nn - uu + 1;
    printf("%d %d\n", uuu, vvv);
  }
  return 0;
}
