#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  int x, y, z, p;
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  x %= 4, y %= 2, z %= 4;
  for (int i = 0; i < p; i++) {
    int r, c, n = ::n, m = ::m;
    scanf("%d%d", &r, &c);
    for (int j = 0; j < x; j++) swap(r = n - r + 1, c), swap(n, m);
    for (int j = 0; j < y; j++) c = m - c + 1;
    for (int j = 0; j < z; j++) swap(r, c = m - c + 1), swap(n, m);
    printf("%d %d\n", r, c);
  }
}
