#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
int main() {
  std::ios_base::sync_with_stdio(0);
  int n, m, x, y, z, p, a, b;
  cin >> n >> m >> x >> y >> z >> p;
  vector<pair<int, int> > v;
  for (int i = 0; i < p; ++i) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  vector<pair<int, int> > Nv;
  int tmp;
  if (x % 4 != 0) {
    int k = x % 4;
    while (k--) {
      for (int i = 0; i < p; ++i) {
        Nv.push_back(make_pair(v[i].second, (n - v[i].first) + 1));
      }
      v = Nv;
      Nv.clear();
      tmp = n;
      n = m;
      m = tmp;
    }
  }
  if (y % 4 != 0) {
    int k = y % 4;
    while (k--) {
      for (int i = 0; i < p; ++i) {
        v[i].second = m - v[i].second + 1;
      }
    }
  }
  Nv.clear();
  if (z % 4 != 0) {
    int k = z % 4;
    while (k--) {
      for (int i = 0; i < p; ++i) {
        Nv.push_back(make_pair(m - v[i].second + 1, (v[i].first)));
      }
      tmp = n;
      n = m;
      m = tmp;
      v = Nv;
      Nv.clear();
    }
  }
  for (int i = 0; i < p; ++i) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}
