#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int n, m, x, y, z, p, xx, yy, nn, mm, nx, ny;
  cin >> n >> m >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  for (i = 0; i < p; i++) {
    nn = n;
    mm = m;
    cin >> xx >> yy;
    if (x == 1) {
      nx = yy;
      ny = nn - xx + 1;
      yy = ny;
      xx = nx;
    }
    if (x == 2) {
      nx = nn - xx + 1;
      ny = mm - yy + 1;
      yy = ny;
      xx = nx;
    }
    if (x == 3) {
      nx = mm - yy + 1;
      ny = xx;
      yy = ny;
      xx = nx;
    }
    if (x % 2 == 1) {
      int tmp;
      tmp = nn;
      nn = mm;
      mm = tmp;
    }
    if (y == 1) {
      ny = mm - yy + 1;
      yy = ny;
    }
    if (z == 3) {
      nx = yy;
      ny = nn - xx + 1;
      yy = ny;
      xx = nx;
    }
    if (z == 2) {
      nx = nn - xx + 1;
      ny = mm - yy + 1;
      yy = ny;
      xx = nx;
    }
    if (z == 1) {
      nx = mm - yy + 1;
      ny = xx;
      yy = ny;
      xx = nx;
    }
    cout << xx << ' ' << yy << endl;
  }
}
