Ping-pong
Contest: Educational Codeforces Round 99 (Rated for Div. 2)
Difficulty rating: 1100
Tags: constructive algorithms, games, math

Alice and Bob play ping-pong with simplified rules.

During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return.

The one who doesn't make a return loses this play. The winner of the play commences the next play. Alice starts the first play.

Alice has $$$x$$$ stamina and Bob has $$$y$$$. To hit the ball (while serving or returning) each player spends $$$1$$$ stamina, so if they don't have any stamina, they can't return the ball (and lose the play) or can't serve the ball (in this case, the other player serves the ball instead). If both players run out of stamina, the game is over.

Sometimes, it's strategically optimal not to return the ball, lose the current play, but save the stamina. On the contrary, when the server commences a play, they have to hit the ball, if they have some stamina left.

Both Alice and Bob play optimally and want to, firstly, maximize their number of wins and, secondly, minimize the number of wins of their opponent.

Calculate the resulting number of Alice's and Bob's wins.

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^6$$$) — Alice's and Bob's initial stamina.

Output format:
For each test case, print two integers — the resulting number of Alice's and Bob's wins, if both of them play optimally.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first test case, Alice serves the ball and spends $$$1$$$ stamina. Then Bob returns the ball and also spends $$$1$$$ stamina. Alice can't return the ball since she has no stamina left and loses the play. Both of them ran out of stamina, so the game is over with $$$0$$$ Alice's wins and $$$1$$$ Bob's wins.

In the second test case, Alice serves the ball and spends $$$1$$$ stamina. Bob decides not to return the ball — he loses the play but saves stamina. Alice, as the winner of the last play, serves the ball in the next play and spends $$$1$$$ more stamina. This time, Bob returns the ball and spends $$$1$$$ stamina. Alice doesn't have any stamina left, so she can't return the ball and loses the play. Both of them ran out of stamina, so the game is over with $$$1$$$ Alice's and $$$1$$$ Bob's win.

In the third test case, Alice serves the ball and spends $$$1$$$ stamina. Bob returns the ball and spends $$$1$$$ stamina. Alice ran out of stamina, so she can't return the ball and loses the play. Bob, as a winner, serves the ball in the next $$$6$$$ plays. Each time Alice can't return the ball and loses each play. The game is over with $$$0$$$ Alice's and $$$7$$$ Bob's wins.

Example input:
3
1 1
2 1
1 7

Example output:
0 1
1 1
0 7

Editorial:
Let's find an answer for a little different version of the game. Let's say that $$$f(x, y)$$$ is the final score if the first player has $$$x$$$ stamina and the second has $$$y$$$ stamina. The first player can either hit the ball or can give up and lose the play.
How to calculate $$$f(x, y)$$$? Obviously, $$$f(0, x) = (0, x)$$$ and $$$f(x, 0) = (x, 0)$$$. Otherwise, the first player can
• either hit the ball: then the player spent $$$1$$$ stamina and now it's to the second player to decide — hit or lose. So basically, we moved to the state $$$f(y, x - 1)$$$ and the answer in this case is $$$\mathit{rev}(f(y, x - 1))$$$ where $$$\mathit{rev}(a, b) = (b, a)$$$;
• or lose the play: then the player doesn't spend any stamina, but the opponent has to serve the ball. He serves the ball, spend $$$1$$$ stamina and return to the state, where the first player decides — hit or lose. Formally, the answer in this case is $$$f(x, y - 1) + (0, 1)$$$.
Looking at $$$f(0, x) = (0, x)$$$, $$$f(x, 0) = (x, 0)$$$ and one of transitions $$$f(x, y - 1) + (0, 1)$$$ we can guess that $$$f(x, y) = (x, y)$$$ and prove it by induction: $$$f(x, y)$$$ is either $$$\mathit{rev}(f(y, x - 1))$$$ or $$$f(x, y - 1) + (0, 1)$$$, but $$$\mathit{rev}(f(y, x - 1)) = \mathit{rev}(y, x - 1) = (x - 1, y)$$$ and $$$f(x, y - 1) + (0, 1) = (x, y - 1) + (0, 1) = (x, y)$$$ and $$$(x, y)$$$ is better than $$$(x - 1, y)$$$, so $$$f(x, y) = (x, y)$$$.
The final step is to note that since Alice starts the first play and has to serve ball — the answer is $$$\mathit{rev}(f(y, x - 1)) = \mathit{rev}(y, x - 1) = (x - 1, y)$$$.