#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, p;
int main() {
  while (scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p) != EOF) {
    x %= 4;
    y %= 2;
    z %= 4;
    while (p--) {
      int xx, yy;
      scanf("%d%d", &xx, &yy);
      int t = x;
      int len = n;
      while (t--) {
        int xxx = xx, yyy = yy;
        xx = yyy;
        yy = len - xxx + 1;
        if (len == m)
          len = n;
        else
          len = m;
      }
      t = y;
      while (t--) {
        if (len == n) {
          yy = m - yy + 1;
        } else if (len == m) {
          yy = n - yy + 1;
        }
      }
      t = 4 - z;
      while (t--) {
        int xxx = xx, yyy = yy;
        xx = yyy;
        yy = len - xxx + 1;
        if (len == m)
          len = n;
        else
          len = m;
      }
      printf("%d %d\n", xx, yy);
    }
  }
  return 0;
}
