#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const long long N = 5005, mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long N, M, x, y, z, p;
  cin >> N >> M >> x >> y >> z >> p;
  vector<pair<long long, long long> > a(p);
  x %= 4, z %= 4;
  y %= 2;
  for (long long i = 0; i < p; i++) {
    long long px, py;
    cin >> px >> py;
    long long n = N, m = M;
    for (long long i = 0; i < x; i++) swap(px, py), py = n - py + 1, swap(n, m);
    if (y) py = m - py + 1;
    for (long long i = 0; i < z; i++) swap(px, py), px = m - px + 1, swap(n, m);
    cout << px << " " << py << "\n";
  }
}
