#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
long long n, m, x, y, z, p;
void rotate_r() {
  for (long long i = 0; i < p; ++i) {
    v[i] = make_pair(v[i].second, n - v[i].first + 1);
  }
  swap(n, m);
}
void gorizont() {
  for (long long i = 0; i < p; ++i) {
    v[i] = make_pair(v[i].first, m - v[i].second + 1);
  }
}
void rotate_l() {
  for (long long i = 0; i < p; ++i) {
    v[i] = make_pair(m - v[i].second + 1, v[i].first);
  }
  swap(n, m);
}
int main() {
  cin >> n >> m >> x >> y >> z >> p;
  v.resize(p);
  for (long long i = 0; i < p; ++i) cin >> v[i].first >> v[i].second;
  x %= 4;
  y %= 2;
  z %= 4;
  for (long long i = 0; i < x; ++i) rotate_r();
  for (long long i = 0; i < y; ++i) gorizont();
  for (long long i = 0; i < z; ++i) rotate_l();
  for (long long i = 0; i < (long long)v.size(); ++i)
    cout << v[i].first << ' ' << v[i].second << '\n';
  cout << endl;
}
