#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
int Map[100005][2];
void RR(int t, int v);
void MM(int t);
void LL(int t);
int n, m, x, y, z, p;
int main() {
  while (scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p) != EOF) {
    x = x % 4;
    y = y % 2;
    z = z % 4;
    int nn = n, mm = m;
    for (int i = 0; i < p; i++) scanf("%d%d", &Map[i][0], &Map[i][1]);
    for (int i = 0; i < p; i++) {
      RR(i, x);
      for (int ii = 0; ii < y; ii++) MM(i);
      RR(i, 3 * z);
      printf("%d %d\n", Map[i][0], Map[i][1]);
      n = nn;
      m = mm;
    }
  }
  return 0;
}
void RR(int t, int v) {
  v = v % 4;
  if (v == 1) {
    int x = Map[t][0];
    int y = Map[t][1];
    Map[t][0] = y;
    Map[t][1] = n - x + 1;
    int tem = n;
    n = m;
    m = tem;
  }
  if (v == 2) {
    int x = Map[t][0];
    int y = Map[t][1];
    Map[t][0] = n + 1 - x;
    Map[t][1] = m + 1 - y;
  }
  if (v == 3) {
    int x = Map[t][0];
    int y = Map[t][1];
    Map[t][0] = m + 1 - y;
    Map[t][1] = x;
    int tem = n;
    n = m;
    m = tem;
  }
}
void MM(int t) {
  int y = Map[t][1];
  Map[t][1] = (m + 1) - y;
}
