#include <bits/stdc++.h>
const int inf = 2000000000, N = 100009;
using namespace std;
int p, ans, n, m, x, y, z, X[N], Y[N], q[N], w[N], i, j;
void right() {
  int i;
  for (i = 0; i < p; i++) {
    X[i] = w[i];
    Y[i] = n - q[i] + 1;
  }
  for (i = 0; i < p; i++) {
    q[i] = X[i];
    w[i] = Y[i];
  }
  swap(n, m);
}
void gp() {
  for (i = 0; i < p; i++) {
    if (m % 2) {
      if (w[i] == m / 2 + m % 2)
        m = m;
      else if (w[i] <= m / 2 + m % 2)
        w[i] = m / 2 + m % 2 + (m / 2 + m % 2 - w[i]);
      else if (w[i] >= m / 2 + m % 2)
        w[i] = m / 2 + m % 2 - (w[i] - (m / 2 + m % 2));
    } else {
      if (w[i] <= m / 2)
        w[i] = m - w[i] + 1;
      else if (w[i] > m / 2)
        w[i] = m - w[i] + 1;
    }
  }
}
int main() {
  cin >> n >> m >> x >> y >> z >> p;
  x = x % 4;
  y = y % 2;
  z = z % 4;
  for (i = 0; i < p; i++) cin >> q[i] >> w[i];
  for (i = 0; i < x; i++) right();
  if (y) gp();
  for (i = 0; i < (4 - z) % 4; i++) right();
  for (i = 0; i < p; i++) cout << q[i] << " " << w[i] << endl;
}
