#include <bits/stdc++.h>
using namespace std;
long long n, m;
void rotaAnti(long long &f, long long &c) {
  long long af = f, ac = c;
  f = m - ac + 1, c = af;
  swap(n, m);
}
void refleja(long long &f, long long &c, int k) {
  if (k == 1) c = m - c + 1;
}
void rotaHor(long long &f, long long &c) {
  long long af = f, ac = c;
  f = ac;
  c = n - af + 1;
  swap(n, m);
}
int main() {
  long long x, y, z, p, N, M;
  while (cin >> N >> M >> x >> y >> z >> p) {
    long long fk, ck;
    x %= 4;
    y %= 2;
    z %= 4;
    for (int i = 0; i < p; i++) {
      n = N;
      m = M;
      cin >> fk >> ck;
      for (int j = 0; j < x; j++) rotaHor(fk, ck);
      refleja(fk, ck, y);
      for (int j = 0; j < z; j++) rotaAnti(fk, ck);
      cout << fk << " " << ck << endl;
    }
  }
}
