#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn], b[maxn];
int main() {
  int n, m, x, y, z, p;
  while (cin >> n >> m >> x >> y >> z >> p) {
    x %= 4;
    y %= 2;
    z %= 4;
    for (int i = 0; i < p; ++i) cin >> a[i] >> b[i];
    for (int i = 0; i < x; ++i) {
      for (int j = 0; j < p; ++j) {
        int rx = b[j], ry = n - a[j] + 1;
        a[j] = rx;
        b[j] = ry;
      }
      swap(n, m);
    }
    for (int i = 0; i < y; ++i) {
      for (int j = 0; j < p; ++j) {
        b[j] = m - (b[j] - 1);
      }
    }
    for (int i = 0; i < 3 * z; ++i) {
      for (int j = 0; j < p; ++j) {
        int rx = b[j], ry = n - a[j] + 1;
        a[j] = rx;
        b[j] = ry;
      }
      swap(n, m);
    }
    for (int i = 0; i < p; ++i) cout << a[i] << " " << b[i] << endl;
  }
  return 0;
}
