#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, z, p;
  scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
  int nn = n, mm = m;
  x = x % 4;
  y = y % 2;
  z = z % 4;
  for (int i = 0; i < p; i++) {
    n = nn;
    m = mm;
    int xx, yy;
    scanf("%d%d", &xx, &yy);
    for (int j = 0; j < x; j++) {
      swap(n, m);
      int nx = yy;
      int ny = m - xx + 1;
      xx = nx;
      yy = ny;
    }
    for (int j = 0; j < y; j++) {
      xx = xx;
      yy = m - yy + 1;
    }
    for (int j = 0; j < z; j++) {
      swap(n, m);
      int nx = n - yy + 1;
      int ny = xx;
      xx = nx;
      yy = ny;
    }
    printf("%d %d\n", xx, yy);
  }
  return 0;
}
