#include <bits/stdc++.h>
using namespace std;
int n, m, xx, xy, xz, p;
int x[100000], y[100000];
void Swap(int& x, int& y) {
  int tmp = x;
  x = y;
  y = tmp;
}
void XoayP(int xx) {
  int i;
  if (xx / 2) {
    for (i = 0; i < p; i++) {
      x[i] = n - x[i] + 1;
      y[i] = m - y[i] + 1;
    }
  }
  if (xx % 2) {
    for (i = 0; i < p; i++) {
      x[i] = n - x[i] + 1;
      Swap(x[i], y[i]);
    }
    Swap(n, m);
  }
}
void Lat() {
  int i;
  for (i = 0; i < p; i++) {
    y[i] = m - y[i] + 1;
  }
}
int main() {
  int i;
  cin >> n >> m >> xx >> xy >> xz >> p;
  for (i = 0; i < p; i++) cin >> x[i] >> y[i];
  xx %= 4;
  xz %= 4;
  xy %= 2;
  XoayP(xx);
  if (xy) Lat();
  XoayP((4 - xz) % 4);
  for (i = 0; i < p; i++) {
    cout << x[i] << " " << y[i] << endl;
  }
}
