Skip to main content

Oracle

Oracle OA-2 2023

Problem Description

You are given three integers A, B, and C. You have an expression as ((A|X)&(B|X)) = C. The task is to determine if a number X exists such that the expression holds and if it does then, print the minimum value of X else print -1.

AND operator ( & ) - Compares each bit of the first operand to the second operand's corresponding bit. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

OR operator ( I ) - returns a 1 in each bit position for which the corresponding bits of either or both operands are 1.

Input format

The first line contains an integer T denoting the number of test cases. T also denotes the number of times you have to run the Find_X function on a different set of inputs.

For each test case:

· The first line contains one integer A.

· The second line contains one integer B.

· The third line contains one integer C.

Output format

For each test case, print the answer in a new line representing the minimum value of X, if X exists, else print -1.

Constraints

1 < T< 100
0 ≤ A,B,C ≤ 10^9

Example

Input: A = 5, B = 6, C = 7
Output: 3
Explanation: The minimum number X which satisfy ((A|X)& (B|X)) = C expression is 3, as (A|X)=(53)=7.(B X)=(63)=7, hence ((A|X)&(B|X)) = (7&7) = 7 = C.