#include <bits/stdc++.h>
int main() {
  int n, m, x, y, z, p, i, j;
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  x %= 4;
  y %= 2;
  z %= 4;
  int r, c, t = p, k, aux;
  while (p--) {
    scanf("%d%d", &i, &j);
    r = n;
    c = m;
    if (x) {
      for (k = 0; k < x; k++) {
        aux = i;
        i = j;
        j = r - aux + 1;
        aux = r;
        r = c;
        c = aux;
      }
    }
    if (y) {
      j = c - j + 1;
    }
    if (z) {
      for (k = 0; k < z; k++) {
        aux = j;
        j = i;
        i = c - aux + 1;
        aux = r;
        r = c;
        c = aux;
      }
    }
    printf("%d %d\n", i, j);
  }
  return 0;
}
