#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  vector<pair<int, int> > c(p);
  for (int i = 0; i < p; i++) cin >> c[i].first >> c[i].second;
  for (int i = 0; i < x; i++) {
    vector<pair<int, int> > d(p);
    for (int j = 0; j < p; j++)
      d[j] = make_pair(c[j].second, n + 1 - c[j].first);
    c = d;
    swap(n, m);
  }
  for (int i = 0; i < y; i++) {
    vector<pair<int, int> > d(p);
    for (int j = 0; j < p; j++)
      d[j] = make_pair(c[j].first, m + 1 - c[j].second);
    c = d;
  }
  for (int i = 0; i < z; i++) {
    vector<pair<int, int> > d(p);
    for (int j = 0; j < p; j++)
      d[j] = make_pair(m + 1 - c[j].second, c[j].first);
    c = d;
    swap(n, m);
  }
  for (int i = 0; i < p; i++) cout << c[i].first << " " << c[i].second << endl;
  return 0;
}
