Skip to main content

Oracle

Oracle OA 2023 - Find X


You are given the following:

Three integers A, B, and C. You have an expression as ((A|X)&(B|X)) = C

Task
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.

Note
The bitwise 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.

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

Function Description

Complete the Find_X function. This function takes the following 3 parameters and returns the minimum value of X. If X exists else returns -1.

· A: Represents an integer A

· B: Represents an integer B

· C: Represents an integer C

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.