#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x;
  int y;
};
void fun1(const int &p, vector<Point> &V_Point, int N) {
  for (int i = 0; i < p; i++) {
    V_Point[i].y = N - (V_Point[i].y - 1);
  }
}
int main() {
  ifstream ff("file.txt");
  int n, m, x, y, z, p;
  cin >> n >> m >> x >> y >> z >> p;
  vector<Point> V_Point(p);
  for (int i = 0; i < p; i++) {
    cin >> V_Point[i].x >> V_Point[i].y;
  }
  int t = x % 4;
  Point T;
  if (t == 1) {
    for (int i = 0; i < p; i++) {
      T.x = V_Point[i].x;
      T.y = V_Point[i].y;
      V_Point[i].y = n - (V_Point[i].x - 1);
      V_Point[i].x = T.y;
    }
  } else if (t == 2) {
    for (int i = 0; i < p; i++) {
      T.x = V_Point[i].x;
      T.y = V_Point[i].y;
      V_Point[i].y = n - (V_Point[i].x - 1);
      V_Point[i].x = T.y;
    }
    for (int i = 0; i < p; i++) {
      T.x = V_Point[i].x;
      T.y = V_Point[i].y;
      V_Point[i].x = T.y;
      V_Point[i].y = m - (T.x - 1);
    }
  } else if (t == 3) {
    for (int i = 0; i < p; i++) {
      T.x = V_Point[i].x;
      T.y = V_Point[i].y;
      V_Point[i].x = m - (V_Point[i].y - 1);
      V_Point[i].y = T.x;
    }
  }
  int t2 = y % 2;
  if (t2 == 1) {
    if (t == 0 || t == 2) {
      fun1(p, V_Point, m);
    } else {
      fun1(p, V_Point, n);
    }
  }
  int t1 = z % 4;
  if (t == 2 || t == 0) {
    if (t1 == 1) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = m - (V_Point[i].y - 1);
        V_Point[i].y = T.x;
      }
    } else if (t1 == 2) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].y = n - (V_Point[i].x - 1);
        V_Point[i].x = T.y;
      }
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = T.y;
        V_Point[i].y = m - (T.x - 1);
      }
    } else if (t1 == 3) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = T.y;
        V_Point[i].y = n - (T.x - 1);
      }
    }
  } else {
    if (t1 == 1) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = n - (V_Point[i].y - 1);
        V_Point[i].y = T.x;
      }
    } else if (t1 == 2) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = n - (V_Point[i].y - 1);
        V_Point[i].y = T.x;
      }
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = m - (V_Point[i].y - 1);
        V_Point[i].y = T.x;
      }
    } else if (t1 == 3) {
      for (int i = 0; i < p; i++) {
        T.x = V_Point[i].x;
        T.y = V_Point[i].y;
        V_Point[i].x = T.y;
        V_Point[i].y = m - (T.x - 1);
      }
    }
  }
  for (int i = 0; i < p; i++) {
    cout << V_Point[i].x << ' ' << V_Point[i].y << endl;
  }
  return 0;
}
