#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vc;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long N, M, x, y, z, p, i, X, Y, j, lplp1, lplp2;
  cin >> N >> M >> x >> y >> z >> p;
  long long opop1 = x % 4;
  long long opop2 = y % 2;
  long long opop3 = z % 4;
  for (i = 1; i <= p; i++) {
    cin >> X >> Y;
    vc.push_back(make_pair(X, Y));
  }
  for (i = 1; i <= opop1; i++) {
    for (j = 0; j <= (int)vc.size() - 1; j++) {
      lplp1 = vc[j].first;
      lplp2 = vc[j].second;
      vc[j].first = vc[j].second;
      vc[j].second = N - lplp1 + 1;
    }
    swap(N, M);
  }
  for (i = 1; i <= opop2; i++) {
    for (j = 0; j <= (int)vc.size() - 1; j++) {
      lplp1 = vc[j].first;
      lplp2 = vc[j].second;
      vc[j].second = M - lplp2 + 1;
    }
  }
  for (i = 1; i <= opop3; i++) {
    for (j = 0; j <= (int)vc.size() - 1; j++) {
      lplp1 = vc[j].first;
      lplp2 = vc[j].second;
      vc[j].first = M - lplp2 + 1;
      vc[j].second = lplp1;
    }
    swap(N, M);
  }
  for (i = 0; i <= (int)vc.size() - 1; i++) {
    cout << vc[i].first << " " << vc[i].second << "\n";
  }
  return 0;
}
