#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int x[111111], y[111111];
int main() {
  int d1, d2, d3;
  cin >> n >> m >> d1 >> d2 >> d3 >> p;
  for (int i = 1; i <= p; ++i) cin >> x[i] >> y[i];
  for (int _i = 1; _i <= d1 % 4; ++_i) {
    for (int i = 1; i <= p; ++i) {
      int ny, nx;
      ny = n - x[i] + 1;
      nx = y[i];
      x[i] = nx;
      y[i] = ny;
    }
    swap(n, m);
  }
  if (d2 & 1)
    for (int i = 1; i <= p; ++i) {
      y[i] = m - y[i] + 1;
    }
  for (int _i = 1; _i <= d3 % 4; ++_i) {
    for (int i = 1; i <= p; ++i) {
      int ny, nx;
      ny = x[i];
      nx = m - y[i] + 1;
      x[i] = nx;
      y[i] = ny;
    }
    swap(n, m);
  }
  for (int i = 1; i <= p; ++i) {
    cout << x[i] << ' ' << y[i] << endl;
  }
  return 0;
}
