#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, x, y, z, p;
int f[maxn][2];
int tmp;
int main() {
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  for (int i = 0; i < p; i++) scanf("%d%d", &f[i][0], &f[i][1]);
  x = x % 4;
  for (int ii = 0; ii < x; ii++) {
    swap(n, m);
    for (int i = 0; i < p; i++) {
      tmp = f[i][0];
      f[i][0] = f[i][1];
      f[i][1] = m - tmp + 1;
    }
  }
  if (y % 2 == 1) {
    for (int i = 0; i < p; i++) f[i][1] = m + 1 - f[i][1];
  }
  x = (3LL * z) % 4;
  for (int ii = 0; ii < x; ii++) {
    swap(n, m);
    for (int i = 0; i < p; i++) {
      tmp = f[i][0];
      f[i][0] = f[i][1];
      f[i][1] = m - tmp + 1;
    }
  }
  for (int i = 0; i < p; i++) printf("%d %d\n", f[i][0], f[i][1]);
  return 0;
}
