#include <bits/stdc++.h>
using namespace std;
void changex(int &x, int &y, int round, int &n, int &m) {
  int t;
  for (int i = 0; i < round; i++) {
    t = y;
    y = (n + 1 - x);
    x = t;
    t = m;
    m = n;
    n = t;
  }
}
void changey(int &x, int &y, int round, int &n, int &m) {
  int t;
  for (int i = 0; i < round; i++) {
    y = m + 1 - y;
  }
}
void changez(int &x, int &y, int round, int &n, int &m) {
  int t;
  for (int i = 0; i < round; i++) {
    t = x;
    x = (m + 1 - y);
    y = t;
    t = m;
    m = n;
    n = t;
  }
}
int main(int argc, char const *argv[]) {
  int n, m, x, y, z, k, px, py;
  while (scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &k) != EOF) {
    x = x % 4;
    y = y % 2;
    z = z % 4;
    for (int i = 0; i < k; i++) {
      int p = n, q = m;
      scanf("%d%d", &px, &py);
      changex(px, py, x, p, q);
      changey(px, py, y, p, q);
      changez(px, py, z, p, q);
      printf("%d %d\n", px, py);
    }
  }
  return 0;
}
