#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
const double inf = 0.000001;
const int INF = ~0U >> 1;
const int mod = 1000000007;
int n, a[maxn], m, x, y, z, p, X, Y;
void clockwise() {
  int i = X, j = Y;
  x %= 4;
  if (x == 1)
    X = j, Y = n - i + 1, swap(n, m);
  else if (x == 2)
    X = n - i + 1, Y = m - j + 1;
  else if (x == 3)
    X = m - j + 1, Y = i, swap(n, m);
}
void h_rotate() {
  y %= 2;
  if (y) {
    Y = m - Y + 1;
  }
}
void counterclockwise() {
  int i = X, j = Y;
  z %= 4;
  if (z == 3)
    X = j, Y = n - i + 1, swap(n, m);
  else if (z == 2)
    X = n - i + 1, Y = m - j + 1;
  else if (z == 1)
    X = m - j + 1, Y = i, swap(n, m);
}
int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    int tx = n, ty = m;
    while (p--) {
      n = tx, m = ty;
      scanf("%d", &X), scanf("%d", &Y);
      clockwise();
      h_rotate();
      counterclockwise();
      printf("%d %d\n", X, Y);
    }
  }
  return 0;
}
