Bobo made a very long sequence of numbers
)
in ICPCCamp where
)
and
Now he wants to ask q questions where the i-th question is to compute the sum of

.
Unfortunately, the only tool which Bobo can utilize is an old broken 4-bit counter.
While trying to answer the i-th question, Bobo will set the counter to 0, and add numbers to the counter in the order of

.
As the counter is broken, adding the number a to a counter holding value x yields
%20%2B%20a%5D%5C%20%5Cmathrm%7Bmod%7D%5C%2016)
.
Note that ``

'' stands for bitwise exclusive or (XOR).
Bobo would like to know the final result.
*Special Note*: The time limit is tight so that some optimization might be necessary. Try to solve the problem as late as possible.
输入描述:
The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains five integers n, m, A, B, q.
The i-th of the following q lines contains three integers
,
and
.
* 
* 
* 
* 
* 
* The number of test cases does not exceed 10.
输出描述:
For each question, output an integer which denotes the result.