#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, p;
void swap(int &u, int &v, int id) {
  if (id == 0) {
    int t = u;
    u = v;
    v = n - t + 1;
    swap(m, n);
  } else if (id == 1) {
    v = m - v + 1;
  } else {
    int t = u;
    u = m - v + 1;
    v = t;
    swap(m, n);
  }
}
int main() {
  int u, v;
  int tm, tn;
  while (scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p) != EOF) {
    tn = n;
    tm = m;
    for (int i = 0; i < p; i++) {
      scanf("%d%d", &u, &v);
      for (int j = 0; j < x % 4; j++) swap(u, v, 0);
      for (int j = 0; j < y % 2; j++) swap(u, v, 1);
      for (int j = 0; j < z % 4; j++) swap(u, v, 2);
      printf("%d %d\n", u, v);
      n = tn;
      m = tm;
    }
  }
  return 0;
}
