#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y, z;
int p;
void fx(int &i, int &j) {
  int ni = j;
  int nj = n - 1 - i;
  i = ni, j = nj;
}
void fy(int &i, int &j) {
  int ni = i;
  int nj = m - 1 - j;
  i = ni, j = nj;
}
void fz(int &i, int &j) {
  int ni = m - 1 - j;
  int nj = i;
  i = ni, j = nj;
}
int main() {
  while (cin >> n >> m) {
    cin >> x >> y >> z;
    x %= 4;
    z %= 4;
    y %= 2;
    cin >> p;
    int on, om;
    on = n, om = m;
    while (p--) {
      n = on, m = om;
      int i, j;
      scanf("%d %d\n", &i, &j);
      i--, j--;
      for (int k = 0; k < x; k++) fx(i, j), swap(n, m);
      for (int k = 0; k < y; k++) fy(i, j);
      for (int k = 0; k < z; k++) fz(i, j), swap(n, m);
      i++, j++;
      printf("%d %d\n", i, j);
    }
  }
}
