#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z, p, savem, saven;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z *= 3;
  z %= 4;
  saven = n, savem = m;
  while (p--) {
    int x1, kjdfshnvoavaofobiopj;
    cin >> x1 >> kjdfshnvoavaofobiopj;
    n = saven, m = savem;
    for (int i = 1; i <= x; i++) {
      int save = kjdfshnvoavaofobiopj;
      kjdfshnvoavaofobiopj = n + 1 - x1;
      x1 = save;
      swap(m, n);
    }
    if (y) kjdfshnvoavaofobiopj = m - kjdfshnvoavaofobiopj + 1;
    for (int i = 1; i <= z; i++) {
      int save = kjdfshnvoavaofobiopj;
      kjdfshnvoavaofobiopj = n + 1 - x1;
      x1 = save;
      swap(m, n);
    }
    cout << x1 << " " << kjdfshnvoavaofobiopj << "\n";
  }
  return 0;
}
