#include <bits/stdc++.h>
using namespace std;
template <class T>
inline long long gcd(T x, T y);
int n, m, p;
const int NMAX = 100004;
struct Point {
  int x, y;
};
Point a[NMAX];
inline void RotateH() {
  for (int i = 1; i <= p; ++i) a[i].y = m - a[i].y + 1;
}
inline void RotateClock() {
  int x, y;
  for (int i = 1; i <= p; ++i) {
    x = a[i].x;
    y = a[i].y;
    a[i].x = y;
    a[i].y = n - x + 1;
  }
  swap(n, m);
}
inline void RotateIClock() {
  int x, y;
  for (int i = 1; i <= p; ++i) {
    x = a[i].x;
    y = a[i].y;
    a[i].y = x;
    a[i].x = m - y + 1;
  }
  swap(n, m);
}
int main() {
  int x, y, z, i;
  cin >> n >> m >> x >> y >> z >> p;
  for (i = 1; i <= p; ++i) cin >> a[i].x >> a[i].y;
  x %= 4;
  y %= 4;
  z %= 4;
  for (i = 1; i <= x; ++i) RotateClock();
  for (i = 1; i <= y; ++i) RotateH();
  for (i = 1; i <= z; ++i) RotateIClock();
  for (i = 1; i <= p; ++i) cout << a[i].x << " " << a[i].y << "\n";
  return 0;
}
template <class T>
inline long long gcd(T x, T y) {
  if (!y) return x;
  return gcd(y, x % y);
}
