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