And-or operations

2.8

5 votes
Basic Programming, Basics of Bit Manipulation, Basic Programming, Easy, Bit Manipulation, Bit manipulation
Problem

You are given the following pseudo code:

res = a
for i = 1 to k
    if i is odd
        res = res & b
    else
        res = res | b

You are also given the values of a, b, and k. Find the final value of res.

Input

  • First line consists of a single integer, T, denoting the number of test cases.
  • Each test case consists of 3 lines, each consisting of a single integer denoting a, b and k respectively.

Output
Print the final value of res for each test case in a new line.

Constraints
1T105
1a,b,k1018

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Since k=1,res=4&5=4

Editor Image

?