Codeforces Round 234 (Div. 2)
C
Inna and Huge Candy Matrix
Codeforces
1500
原题
← BD →
翻译中…

Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from $1$ to $*n*$ from top to bottom and the columns — from $1$ to $*m*$, from left to right. We'll represent the cell on the intersection of the $*i*$-th row and $*j*$-th column as $(*i*, *j*)$. Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has $*p*$ candies: the $*k*$-th candy is at cell $(*x*_{*k*}, *y*_{*k*})$.

翻译中…

The time moved closer to dinner and Inna was already going to eat $*p*$ of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix $*x*$ times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix $*y*$ times. And then he rotated the matrix $*z*$ times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

翻译中…

image

翻译中…

Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

翻译中…

Input

翻译中…

The first line of the input contains fix integers $*n*$, $*m*$, $*x*$, $*y*$, $*z*$, $*p*$ $(1 ≤ *n*, *m* ≤ 10^{9}; 0 ≤ *x*, *y*, *z* ≤ 10^{9}; 1 ≤ *p* ≤ 10^{5})$.

翻译中…

Each of the following $*p*$ lines contains two integers $*x*_{*k*}$, $*y*_{*k*}$ $(1 ≤ *x*_{*k*} ≤ *n*; 1 ≤ *y*_{*k*} ≤ *m*)$ — the initial coordinates of the $*k*$-th candy. Two candies can lie on the same cell.

翻译中…

Output

翻译中…

For each of the $*p*$ candies, print on a single line its space-separated new coordinates.

翻译中…

Note

翻译中…

Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:

翻译中…

QWER      REWQ
ASDF  ->  FDSA
ZXCV      VCXZ

翻译中…

样例

Input #1
3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output #1
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1
InputCopy OutputCopy
题目信息
题号
400C
时间限制
2 s
内存限制
256 MB
标签
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。