Broken Counter
题号:NC52846
时间限制:C/C++/Rust/Pascal 8秒,其他语言16秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld

题目描述

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 .
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 l_i, r_i and w_i.

*
*
*
*
*
* The number of test cases does not exceed 10.

输出描述:

For each question, output an integer which denotes the result.
示例1

输入

复制
5 2 1 1 2
1 4 0
2 5 1

输出

复制
2
15