#P15318. [VKOSHP 2025] System of Equations with XOR

[VKOSHP 2025] System of Equations with XOR

Description

Alice and Bob love problems involving random numbers. One day they came up with the following problem:

  • First, Alice chooses a random integer xx from the range of 11 to 23112^{31} - 1, all numbers are equally likely.
  • Then, Bob chooses a random integer yy from the range of 11 to 23112^{31} - 1, all numbers are equally likely.
  • They calculate the product of these numbers a=xya = x \cdot y and their bitwise XOR b=xyb = x \oplus y.

You are given two resulting integers aa and bb. Find any pair of natural numbers xx and yy such that:

xy=aandxy=b,xy = a \quad \text{and} \quad x \oplus y = b,

where \oplus denotes the bitwise XOR operation.

Recall that the bitwise "exclusive or" (\oplus, xor) of two non-negative integers is defined as follows: write both numbers in binary representation; the ii-th binary digit of the result is 1 if exactly one of the arguments has it equal to 1. For example, (1414 xor 77) = (11102011121110_2 \oplus 0111_2) = 100121001_2 = 99.

Input Format

The first line of the input contains a single integer tt (1t200000)(1 \leq t \leq 200\,000) --- the number of test cases.

In the following tt lines of input, there are two integers aa and bb (1a<2621 \leq a < 2^{62}, 0b<2310 \leq b < 2^{31}) --- the description of the next test case.

Output Format

For each test case, output in a separate line two natural numbers xx and yy, separated by a space, such that xy=axy = a and xy=bx \oplus y = b.

If there are multiple valid answers, you may output any of them.

2
21 4
9 0
7 3
3 3

Hint

In this problem, there are 100100 tests, including the example from the statement. It is guaranteed that in all tests, except for the example from the statement, t=200000t = 200\,000, and the numbers aa and bb for each test case were generated by choosing random numbers xx and yy by Alice and Bob.