#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p, a, b;
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  x %= 4;
  y %= 2;
  z %= 4;
  for (int i = 0; i < p; i++) {
    int tx = x, ty = y, tz = z, tn = n, tm = m;
    scanf("%d%d", &a, &b);
    while (tx--) {
      int temp = a;
      a = b;
      b = tn + 1 - temp;
      swap(tn, tm);
    }
    if (ty) b = tm + 1 - b;
    tz = 4 - tz;
    while (tz--) {
      int temp = a;
      a = b;
      b = tn + 1 - temp;
      swap(tn, tm);
    }
    printf("%d %d\n", a, b);
  }
  return 0;
}
