#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m, x, y, z, p, xk, yk;
  cin >> n >> m >> x >> y >> z >> p;
  x &= 3;
  y &= 1;
  z &= 3;
  z = 4 - z;
  for (__typeof(p) i = (0) - ((0) > (p)); i != (p) - ((0) > (p));
       i += 1 - 2 * ((0) > (p))) {
    cin >> xk >> yk;
    int curn = n, curm = m;
    for (__typeof(x) j = (0) - ((0) > (x)); j != (x) - ((0) > (x));
         j += 1 - 2 * ((0) > (x))) {
      xk = curn - xk + 1;
      swap(curn, curm);
      swap(xk, yk);
    }
    if (y) {
      yk = curm - yk + 1;
    }
    for (__typeof(z) j = (0) - ((0) > (z)); j != (z) - ((0) > (z));
         j += 1 - 2 * ((0) > (z))) {
      xk = curn - xk + 1;
      swap(curn, curm);
      swap(xk, yk);
    }
    cout << xk << ' ' << yk << endl;
  }
  return 0;
}
