#K51852. Traffic Light Sequence
Traffic Light Sequence
Traffic Light Sequence
Given a starting state \(S\), a toggle value \(B\), and an integer \(K\) representing the number of iterations, determine the final state of the traffic light after \(K\) iterations.
The update rule is defined as follows:
- If \(K\) is even, the final state remains \(S\).
- If \(K\) is odd, the final state becomes \(S \oplus B\), where \(\oplus\) denotes the bitwise XOR operation.
For example, when \(S = 5\), \(B = 3\), and \(K = 1\), since 1 is odd the final state is \(5 \oplus 3 = 6\). Similarly, when \(S = 2\), \(B = 7\), and \(K = 4\), since 4 is even the final state remains 2.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains three space-separated integers \(S\), \(B\), and \(K\), where:
- \(S\) is the starting state of the traffic light.
- \(B\) is the toggle value used for the XOR operation.
- \(K\) is the number of iterations applied.
outputFormat
For each test case, output the final state of the traffic light on a new line.
## sample2
5 3 1
2 7 4
6
2
</p>