#include <bits/stdc++.h>
using namespace std;
int x, y, z, n, m, a, b, c, tmp, t, t2, tmp2;
int main() {
  cin >> n >> m >> x >> y >> z >> c;
  for (int i = 1; i <= c; i++) {
    t = m, t2 = n;
    cin >> a >> b;
    for (int j = 1; j <= x % 4; j++) {
      tmp = a, a = b, b = abs(abs(tmp - 1) - t2);
      tmp2 = t2, t2 = t, t = tmp2;
    }
    for (int j = 1; j <= y % 2; j++) b = abs(abs(1 - b) - t);
    if (z % 4 == 1)
      for (int j = 1; j <= 3; j++) {
        tmp = a, a = b, b = abs(abs(tmp - 1) - t2);
        tmp2 = t2, t2 = t, t = tmp2;
      }
    else if (z % 4 == 2)
      for (int j = 1; j <= 2; j++) {
        tmp = a, a = b, b = abs(abs(tmp - 1) - t2);
        tmp2 = t2, t2 = t, t = tmp2;
      }
    else if (z % 4 == 3)
      for (int j = 1; j <= 1; j++) {
        tmp = a, a = b, b = abs(abs(tmp - 1) - t2);
        tmp2 = t2, t2 = t, t = tmp2;
      }
    cout << a << " " << b << endl;
  }
  return 0;
}
