#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, l, x, y, z, p, temp;
  cin >> n >> m >> x >> y >> z >> p;
  int pm = m, pn = n;
  while (p--) {
    m = pm;
    n = pn;
    cin >> i >> j;
    int tx, ty;
    if (x % 4 == 0) {
      tx = i;
      ty = j;
    } else if (x % 4 == 1) {
      tx = j;
      ty = n - i + 1;
      temp = m;
      m = n;
      n = temp;
    } else if (x % 4 == 2) {
      tx = n - i + 1;
      ty = m - j + 1;
    } else if (x % 4 == 3) {
      tx = m - j + 1;
      ty = i;
      temp = m;
      m = n;
      n = temp;
    }
    i = tx;
    j = ty;
    if (y % 2 != 0) {
      tx = i;
      ty = m - j + 1;
    }
    i = tx;
    j = ty;
    if (z % 4 == 0) {
      tx = i;
      ty = j;
    } else if (z % 4 == 3) {
      tx = j;
      ty = n - i + 1;
    } else if (z % 4 == 2) {
      tx = n - i + 1;
      ty = m - j + 1;
    } else if (z % 4 == 1) {
      tx = m - j + 1;
      ty = i;
    }
    cout << tx << " " << ty << endl;
  }
  return 0;
}
