#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, q;
void look(int a, int b) {
  int Ln = n, Lm = m, num = 0;
  while (num != x) {
    int temp = b;
    b = Ln + 1 - a;
    a = temp;
    temp = Ln;
    Ln = Lm;
    Lm = temp;
    num++;
  }
  num = 0;
  if (y > 0) {
    b = Lm - b + 1;
  }
  num = (4 - z) % 4;
  while (num) {
    num--;
    int temp = b;
    b = Ln + 1 - a;
    a = temp;
    temp = Ln;
    Ln = Lm;
    Lm = temp;
  }
  printf("%d %d\n", a, b);
}
int main() {
  while (scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &q) == 6) {
    x = x % 4;
    y = y % 2;
    z = z % 4;
    for (int i = 0; i < q; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      look(a, b);
    }
  }
  return 0;
}
