#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, i, j, t;
  int a, b, c, p;
  scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &p);
  int nn = n, mm = m;
  for (i = 1; i <= p; i++) {
    n = nn;
    m = mm;
    scanf("%d%d", &x, &y);
    if (a % 4 != 0) {
      a = a % 4;
      for (j = 1; j <= a; j++) {
        t = x;
        x = y;
        y = n - t + 1;
        swap(n, m);
      }
    }
    if (b % 2 != 0) y = m - y + 1;
    if (c % 4 != 0) {
      c = c % 4;
      for (j = 1; j <= c; j++) {
        t = x;
        x = m - y + 1;
        y = t;
        swap(n, m);
      }
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}
