#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, N = 1e6 + 1;
int main() {
  long long n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  long long n1 = n, m1 = m;
  x = x % 4;
  y = y % 2;
  z = z % 4;
  for (long long i = 0; i < p; i++) {
    n = n1, m = m1;
    long long a, b;
    cin >> a >> b;
    for (long long j = 0; j < x; j++) {
      long long temp = a;
      a = b;
      b = n - temp + 1;
      swap(m, n);
    }
    for (long long j = 0; j < y; j++) {
      b = m - b + 1;
    }
    for (long long j = 0; j < 3 * z; j++) {
      long long temp = a;
      a = b;
      b = n - temp + 1;
      swap(n, m);
    }
    cout << a << " " << b << endl;
  }
  return 0;
}
