#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, p, a[200001], b[200001], nx, ny, mm, nn;
void r(int x, int y) {
  int nx = y, ny = n - x + 1;
  cout << nx << " " << ny << "\n";
}
int main() {
  scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &z, &p);
  mm = m;
  x = x % 4;
  y = y % 2;
  z = z % 4;
  for (int i = 1; i <= p; i++) scanf("%d %d\n", &a[i], &b[i]);
  if (x == 1) {
    for (int i = 1; i <= p; i++) {
      nx = b[i];
      ny = n - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
    }
  } else if (x == 2) {
    for (int i = 1; i <= p; i++) {
      nx = b[i];
      ny = n - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
      nx = b[i];
      ny = m - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
    }
  } else if (x == 3) {
    for (int i = 1; i <= p; i++) {
      nx = b[i];
      ny = n - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
      nx = b[i];
      ny = m - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
      nx = b[i];
      ny = n - a[i] + 1;
      a[i] = nx;
      b[i] = ny;
    }
  }
  if (x % 2 == 0) {
    nn = n;
    mm = m;
  } else {
    nn = m;
    mm = n;
  }
  if (y == 1) {
    for (int i = 1; i <= p; i++) {
      nx = a[i];
      ny = mm - b[i] + 1;
      a[i] = nx;
      b[i] = ny;
    }
  }
  if (z == 1) {
    for (int i = 1; i <= p; i++) {
      nx = mm - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
    }
  } else if (z == 2) {
    for (int i = 1; i <= p; i++) {
      nx = mm - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
      nx = nn - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
    }
  } else if (z == 3) {
    for (int i = 1; i <= p; i++) {
      nx = mm - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
      nx = nn - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
      nx = mm - b[i] + 1;
      ny = a[i];
      a[i] = nx;
      b[i] = ny;
    }
  }
  for (int i = 1; i <= p; i++) printf("%d %d\n", a[i], b[i]);
  return 0;
}
