#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  for (long long i = 0; i < p; i++) {
    long long x1, y1;
    cin >> x1 >> y1;
    for (long long j = x, tmpn = n; j > 0; j--) {
      double polx = (tmpn + 1) * 1.0 / 2;
      x1 = polx + (polx - x1);
      long long x2 = x1;
      x1 = y1;
      y1 = x2;
      if (tmpn == n) {
        tmpn = m;
      } else
        tmpn = n;
    }
    if (y == 1) {
      double poly = ((x % 2 ? n : m) + 1) * 1.0 / 2;
      y1 = poly + (poly - y1);
    }
    for (long long j = z, tmpm = (x % 2 ? n : m); j > 0; j--) {
      double poly = (tmpm + 1) * 1.0 / 2;
      y1 = poly + (poly - y1);
      long long y2 = y1;
      y1 = x1;
      x1 = y2;
      if (tmpm == n) {
        tmpm = m;
      } else
        tmpm = n;
    }
    cout << x1 << " " << y1 << endl;
  }
}
