#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x;
  int y;
};
void fun1(const int &p, vector<Point> &V_Point, int N) {
  for (int i = 0; i < p; i++) {
    V_Point[i].y = N - (V_Point[i].y - 1);
  }
}
void fun2(const int &p, vector<Point> &V_Point, int N) {
  Point T;
  for (int i = 0; i < p; i++) {
    T.x = V_Point[i].x;
    T.y = V_Point[i].y;
    V_Point[i].x = T.y;
    V_Point[i].y = N - (T.x - 1);
  }
}
void fun4(const int &p, vector<Point> &V_Point, int N) {
  Point T;
  for (int i = 0; i < p; i++) {
    T.x = V_Point[i].x;
    T.y = V_Point[i].y;
    V_Point[i].x = N - (T.y - 1);
    V_Point[i].y = T.x;
  }
}
int main() {
  ifstream ff("file.txt");
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  vector<Point> V_Point(p);
  for (int i = 0; i < p; i++) {
    scanf("%d%d", &V_Point[i].x, &V_Point[i].y);
  }
  int t = x % 4;
  Point T;
  if (t == 1) {
    fun2(p, V_Point, n);
  } else if (t == 2) {
    fun2(p, V_Point, n);
    fun2(p, V_Point, m);
  } else if (t == 3) {
    fun4(p, V_Point, m);
  }
  int t2 = y % 2;
  if (t2 == 1) {
    if (t == 0 || t == 2) {
      fun1(p, V_Point, m);
    } else {
      fun1(p, V_Point, n);
    }
  }
  int t1 = z % 4;
  if (t == 2 || t == 0) {
    if (t1 == 1) {
      fun4(p, V_Point, m);
    } else if (t1 == 2) {
      fun2(p, V_Point, n);
      fun2(p, V_Point, m);
    } else if (t1 == 3) {
      fun2(p, V_Point, n);
    }
  } else {
    if (t1 == 1) {
      fun4(p, V_Point, n);
    } else if (t1 == 2) {
      fun4(p, V_Point, n);
      fun4(p, V_Point, m);
    } else if (t1 == 3) {
      fun2(p, V_Point, m);
    }
  }
  for (int i = 0; i < p; i++) {
    cout << V_Point[i].x << ' ' << V_Point[i].y << endl;
  }
  return 0;
}
