#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> rot_cw(long long f, long long s, long long n) {
  long long newf = s;
  long long news = n - f - 1;
  return make_pair(newf, news);
}
pair<long long, long long> rot_90(long long f, long long s, long long n,
                                  long long m) {
  long long newf = n - f - 1;
  long long news = m - s - 1;
  return make_pair(newf, news);
}
pair<long long, long long> rot_ccw(long long f, long long s, long long col) {
  long long newf = col - 1 - s;
  long long news = f;
  return make_pair(newf, news);
}
int main() {
  long long n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  pair<long long, long long> niza[p];
  for (int i = 0; i < p; i++) {
    cin >> niza[i].first >> niza[i].second;
    niza[i].first--;
    niza[i].second--;
  }
  for (int i = 0; i < p; i++) {
    if (x == 1) {
      niza[i] = rot_cw(niza[i].first, niza[i].second, n);
    } else if (x == 2) {
      niza[i] = rot_90(niza[i].first, niza[i].second, n, m);
    } else if (x == 3) {
      niza[i] = rot_ccw(niza[i].first, niza[i].second, m);
    }
  }
  if (x % 2 == 1) {
    swap(n, m);
  }
  for (int i = 0; i < p; i++) {
    if (y % 2 == 1) {
      niza[i].second = m - niza[i].second - 1;
    }
  }
  for (int i = 0; i < p; i++) {
    if (z == 1) {
      niza[i] = rot_ccw(niza[i].first, niza[i].second, m);
    } else if (z == 2) {
      niza[i] = rot_90(niza[i].first, niza[i].second, n, m);
    } else if (z == 3) {
      niza[i] = rot_cw(niza[i].first, niza[i].second, n);
    }
  }
  for (int i = 0; i < p; i++) {
    cout << niza[i].first + 1 << " " << niza[i].second + 1 << endl;
  }
  return 0;
}
