#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
bool ascending(int i, int j) { return (i < j); }
bool descending(int i, int j) { return (i > j); }
using namespace std;
int n, m;
pair<int, int> rotate1(pair<int, int> p, int num) {
  for (int(i) = 0; (i) < (num); (i)++) {
    swap(p.first, p.second);
    swap(n, m);
    p.second = m - p.second + 1;
  }
  return p;
}
pair<int, int> rotate2(pair<int, int> p) {
  p.second = m - p.second + 1;
  return p;
}
int main() {
  ios::sync_with_stdio(0);
  int N, M;
  int x, y, z, p;
  cin >> N >> M >> x >> y >> z >> p;
  x %= 4;
  y %= 2;
  z %= 4;
  for (int(i) = 0; (i) < (p); (i)++) {
    n = N, m = M;
    pair<int, int> a;
    cin >> a.first >> a.second;
    a = rotate1(a, x);
    if (y) a = rotate2(a);
    a = rotate1(a, 4 - z);
    cout << a.first << " " << a.second << endl;
  }
}
