#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int r, c, clock, horiz, aclock, p, px, py, tmp, R, C;
  scanf("%d", &r);
  scanf("%d", &c);
  scanf("%d", &clock);
  scanf("%d", &horiz);
  scanf("%d", &aclock);
  scanf("%d", &p);
  R = r;
  C = c;
  horiz %= 2;
  clock %= 4;
  aclock %= 4;
  for (i = (1); i < (p + 1); i++) {
    scanf("%d", &px);
    scanf("%d", &py);
    for (j = (1); j < (clock + 1); j++) {
      tmp = px;
      px = py;
      py = r - tmp + 1;
      swap(r, c);
    }
    if (horiz & 1) py = c - py + 1;
    for (j = (1); j < (aclock + 1); j++) {
      tmp = py;
      py = px;
      px = c - tmp + 1;
      swap(r, c);
    }
    printf("%d", px);
    printf(" ");
    printf("%d", py);
    printf("\n");
    r = R;
    c = C;
  }
  return 0;
}
