#include <bits/stdc++.h>
const int MAXP = 100001;
int n, m, x, y, z, p;
void rotate(int &xi, int &yi) {
  int temp = yi;
  yi = n - xi + 1;
  xi = temp;
}
void reflect(int &yi) { yi = m - yi + 1; }
int main() {
  std::cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z = 4 - (z % 4);
  int answer_x[MAXP], answer_y[MAXP];
  for (int i = 0; i < p; ++i) {
    int ni = n, mi = m;
    int xk, yk;
    std::cin >> xk >> yk;
    for (int j = 0; j < x; ++j) {
      rotate(xk, yk);
      int temp = n;
      n = m;
      m = temp;
    }
    if (y) reflect(yk);
    for (int j = 0; j < z; ++j) {
      rotate(xk, yk);
      int temp = n;
      n = m;
      m = temp;
    }
    answer_x[i] = xk;
    answer_y[i] = yk;
    n = ni;
    m = mi;
  }
  for (int i = 0; i < p; ++i)
    std::cout << answer_x[i] << ' ' << answer_y[i] << std::endl;
  return 0;
}
