#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p, n1, m1;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  n1 = n;
  m1 = m;
  int a, b, a1, b1;
  for (int i = 0; i < p; ++i) {
    n = n1;
    m = m1;
    scanf("%d%d", &a, &b);
    for (int i1 = 0; i1 < x; ++i1) {
      a1 = b;
      b1 = n + 1 - a;
      a = a1;
      b = b1;
      swap(m, n);
    }
    for (int i1 = 0; i1 < y; ++i1) {
      b = (m + 1) - b;
    }
    for (int i1 = 0; i1 < z; ++i1) {
      a1 = (m + 1) - b;
      b1 = a;
      a = a1;
      b = b1;
      swap(m, n);
    }
    printf("%d %d\n", a, b);
  }
}
