#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
const int MN = 2e+7;
int n, m, nn, mm;
int i, j, k, x, y, z, p, u, v;
int d[2000], tt;
char ss[2000][2000];
void change() {
  int n = nn, m = mm;
  if (x == 1) {
    int tmp = u;
    u = v;
    v = n - tmp + 1;
    swap(n, m);
  }
  if (x == 2) {
    u = n - u + 1;
    v = m - v + 1;
  }
  if (x == 3) {
    int tmp = v;
    v = u;
    u = m - tmp + 1;
    swap(n, m);
  }
  if (y == 1) {
    v = m - v + 1;
  }
  if (z == 3) {
    int tmp = u;
    u = v;
    v = n - tmp + 1;
  }
  if (z == 2) {
    u = n - u + 1;
    v = m - v + 1;
  }
  if (z == 1) {
    int tmp = v;
    v = u;
    u = m - tmp + 1;
  }
}
int main() {
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  nn = n;
  mm = m;
  x = x % 4;
  y = y % 2;
  z = z % 4;
  for (i = 1; i <= p; i++) {
    scanf("%d%d", &u, &v);
    change();
    printf("%d %d\n", u, v);
  }
  return 0;
}
