#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000");
using namespace std;
void Change(int &tx, int &ty, int n, int m, int x, int y, int z) {
  int tmp;
  while (x--) {
    tmp = tx;
    tx = ty;
    ty = n - tmp + 1;
    swap(n, m);
  }
  while (y--) {
    ty = m - ty + 1;
  }
  while (z--) {
    tmp = ty;
    ty = tx;
    tx = m - tmp + 1;
    swap(n, m);
  }
}
int main() {
  int n, m, x, y, z, p, tx, ty;
  scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &z, &p);
  x %= 4, y %= 2, z %= 4;
  while (p--) {
    scanf("%d %d", &tx, &ty);
    Change(tx, ty, n, m, x, y, z);
    printf("%d %d\n", tx, ty);
  }
  return 0;
}
