#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, p, rn, rm;
pair<int, int> now;
pair<int, int> ccw(pair<int, int> q) {
  pair<int, int> ret = make_pair(m - q.second + 1, q.first);
  swap(n, m);
  return ret;
}
pair<int, int> hr(pair<int, int> q) {
  return make_pair(q.first, m - q.second + 1);
}
pair<int, int> cw(pair<int, int> q) { return hr(ccw(hr(q))); }
int main() {
  if (fopen("C.in", "r")) freopen("C.in", "r", stdin);
  cin >> n >> m >> x >> y >> z >> p;
  rn = n;
  rm = m;
  x %= 4;
  y %= 2;
  z %= 4;
  for (int i = 0; i < p; i++) {
    scanf("%d %d", &now.first, &now.second);
    for (int j = 0; j < x; j++) {
      now = cw(now);
    }
    for (int j = 0; j < y; j++) {
      now = hr(now);
    }
    for (int j = 0; j < z; j++) {
      now = ccw(now);
    }
    printf("%d %d\n", now.first, now.second);
    n = rn;
    m = rm;
  }
  return 0;
}
