#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  double mid1 = (n + 1) / 2.0;
  double mid2 = (m + 1) / 2.0;
  while (p--) {
    int x1, y1;
    cin >> x1 >> y1;
    double x2 = (double)x1 - mid1;
    double y2 = (double)y1 - mid2;
    int xx = x;
    xx %= 4;
    int sum = xx;
    while (xx--) {
      double temp = x2;
      x2 = y2;
      y2 = -1 * temp;
    }
    int yy = y;
    yy %= 2;
    while (yy--) {
      y2 = -1 * y2;
    }
    int zz = z;
    zz %= 4;
    sum += 4 - zz;
    while (zz--) {
      double temp = x2;
      x2 = -1 * y2;
      y2 = temp;
    }
    if (sum % 2 == 0) {
      x1 = (int)(x2 + mid1);
      y1 = (int)(y2 + mid2);
    } else {
      x1 = (int)(x2 + mid2);
      y1 = (int)(y2 + mid1);
    }
    cout << x1 << " " << y1 << endl;
  }
  return 0;
}
