#include <bits/stdc++.h>
using namespace std;
int matrix[100005][5];
int n, m, x, y, z, p;
void swap_(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
void clockwise(int xx) {
  for (int j = 0; j < xx; j++) {
    for (int i = 1; i <= p; i++) swap(matrix[i][0], matrix[i][1]);
    swap_(&n, &m);
    for (int i = 1; i <= p; i++) matrix[i][1] = m + 1 - matrix[i][1];
  }
}
void horizontal(int yy) {
  for (int j = 0; j < yy; j++) {
    for (int i = 1; i <= p; i++) matrix[i][1] = m + 1 - matrix[i][1];
  }
}
void counterclockwise(int zz) {
  for (int j = 0; j < zz; j++) {
    for (int i = 1; i <= p; i++) swap(matrix[i][0], matrix[i][1]);
    swap_(&n, &m);
    for (int i = 1; i <= p; i++) matrix[i][0] = n + 1 - matrix[i][0];
  }
}
int main(void) {
  scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &z, &p);
  for (int i = 1; i <= p; i++) {
    for (int j = 0; j < 2; j++) scanf("%d", &matrix[i][j]);
  }
  clockwise(x % 4);
  horizontal(y % 2);
  counterclockwise(z % 4);
  for (int i = 1; i <= p; i++) {
    printf("%d %d\n", matrix[i][0], matrix[i][1]);
  }
  return 0;
}
