#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
pair<long long, long long> color(pair<long long, long long> a, long long m) {
  return make_pair((a.second), (m - 1 - a.first));
}
pair<long long, long long> counter(pair<long long, long long> a, long long m) {
  return make_pair((m - 1 - a.second), (a.first));
}
pair<long long, long long> hor(pair<long long, long long> a, long long m) {
  return make_pair((a.first), (m - 1 - a.second));
}
void solution() {
  long long n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  long long tn = n, tm = m;
  for (int i = 0; i < int(p); i++) {
    pair<long long, long long> temp;
    cin >> temp.first >> temp.second;
    n = tn, m = tm;
    temp.first--;
    temp.second--;
    x %= 4;
    for (int i = 0; i < int(x); i++) {
      temp = color(temp, n);
      swap(n, m);
    }
    y %= 2;
    for (int i = 0; i < int(y); i++) temp = hor(temp, m);
    z %= 4;
    for (int i = 0; i < int(z); i++) {
      temp = counter(temp, m);
      swap(n, m);
    }
    cout << temp.first + 1 << " " << temp.second + 1 << endl;
  }
}
int main() {
  double beg = clock();
  ios::sync_with_stdio(false);
  solution();
  return 0;
}
