#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, x, y, z, p, a, b, c, u, v, w;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  u = x;
  v = y;
  w = z;
  while (p--) {
    cin >> a >> b;
    x = u;
    y = v;
    z = w;
    while (x-- > 0) {
      c = a;
      a = b;
      b = n - c + 1;
      swap(n, m);
    }
    if (y) b = m - b + 1;
    while (z-- > 0) {
      c = a;
      a = m - b + 1;
      b = c;
      swap(n, m);
    }
    cout << a << " " << b << endl;
    if ((u + w) & 1) swap(n, m);
  }
  return 0;
}
