AlgoUniversity
  • Go Back
Discussion
Boolean Evaluation :

Author

Ujjwal Srivastava

Difficulty Level : Easy

Submissions : 1548

Asked In : Google

Marks :10

: 12 | : 1

You are given 3 integers $$$A$$$, $$$B$$$, and $$$C$$$. You have an expression as $$$$$$((A|X)&(B|X)) = C.$$$$$$

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.

Input

The first line contains $$$T$$$, the number of test cases. For each test case the next 3 lines contains one parameter each namely A,B and C respectively where $$$(0 \le A,B,C \le 10^9).$$$

Output

Output the minimum value of $$$X$$$ if $$$X$$$ exists else return -1.

Example

Input
2
8
11
9
3
2
1
Output
1
-1

Note

The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.