#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
pair<int, int> c[maxn];
int n, m, x, y, z, p;
inline pair<int, int> go(pair<int, int> root) {
  pair<int, int> ans = root;
  int ttt[2];
  ttt[0] = n;
  ttt[1] = m;
  int pro = 0;
  if (x >= 1) {
    ans.first = root.second;
    ans.second = ttt[pro] - (root.first) + 1;
    root.first = ans.first;
    root.second = ans.second;
    pro = !pro;
  }
  if (x >= 2) {
    ans.first = root.second;
    ans.second = ttt[pro] - (root.first) + 1;
    root.first = ans.first;
    root.second = ans.second;
    pro = !pro;
  }
  if (x == 3) {
    ans.first = root.second;
    ans.second = ttt[pro] - (root.first) + 1;
    root.first = ans.first;
    root.second = ans.second;
    pro = !pro;
  }
  pro = !pro;
  if (y == 1) {
    double pt = ((double)(ttt[pro] + 1) / (double)2);
    pt = pt - double(ans.second);
    ans.second += (pt * double(2));
    root.second = ans.second;
  }
  if (z >= 1) {
    ans.first = ttt[pro] - root.second + 1;
    ans.second = root.first;
    root.first = ans.first;
    root.second = ans.second;
    pro = !pro;
  }
  if (z >= 2) {
    ans.first = ttt[pro] - root.second + 1;
    ans.second = root.first;
    root.first = ans.first;
    root.second = ans.second;
    pro = !pro;
  }
  if (z == 3) {
    ans.first = ttt[pro] - root.second + 1;
    ans.second = root.first;
    pro = !pro;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> x >> y >> z >> p;
  for (int i = 1; i <= p; i++) cin >> c[i].first >> c[i].second;
  x %= 4;
  y %= 2;
  z %= 4;
  cout << endl;
  for (int i = 1; i <= p; i++) {
    pair<int, int> tmp = go(c[i]);
    cout << tmp.first << ' ' << tmp.second << endl;
  }
  return 0;
}
