Hide

Problem P
Mirror Maze

George’s birthday is coming up, and his friends are excitedly planning his birthday party. They have already bought his presents and are now planning out the location for the party. After some deliberation, they have decided to host George’s party in a mirror maze. Each section of the mirror maze consists of two parallel walls facing each other on which mirrors are placed. This creates the effect of seeing infinite reflections of oneself if you look at one of the walls.

George’s friends did some research on how to build mirror mazes, and they discovered that a section of a mirror maze is fun only if the $k$-th reflection of the viewer appears $d$ meters away when the viewer looks at one of the mirrors. George’s friends feel confident that they can now build the mirror maze, but they need help figuring out where to put the mirrors so that George will have the most fun. They are planning on building $n$ sections of the maze, and they know when George enters a section of the maze he will be looking to the left. For each section of the maze, they will build a mirror $x$ meters to the left of where George will be and $y$ meters to the right. Because of construction constraints, the distances $x$ and $y$ must be integers between $1$ and $10^9$. Help George’s friends figure out where to place the mirrors for each section such that the $k$-th reflection is $d$ meters away or determine it is impossible to place the mirrors to construct a fun section.

Input

The first line of input is $n$ ($1 \leq n \leq 10^5$), the number of sections in the maze.

Each of the next $n$ lines will consist of two numbers $k$ and $d$ ($1 \leq k,d \leq 10^9$), where $d$ is the distance in meters where the $k$-th reflection should appear.

Output

Output $n$ lines, one for each section of the maze. For each section, output two numbers, $x$ and $y$, the left and right distances of the mirrors, or “impossible” (without quotes) if no combination of left and right distances will result in the $k$-th reflection appearing $d$ meters away.

There may be more than $1$ pair of $x$ and $y$ that satisfy the constraints, you may print any such pair as long as $1 \leq x,y \leq 10^9$. It can be shown that if it is possible to place mirrors to create a fun section then there is a pair $x$ and $y$ such that $1 \leq x,y \leq 10^9$ which creates a fun section.

Sample Explanation

  • In the first section of the maze, placing a mirror 3 meters to the left will cause the first reflection to appear 6 meters away.

  • In the second section of the maze and by placing the mirrors 1 meter left and 6 meters right, the first reflection appears 2 meters away, the second reflection appears 14 meters away, and the third reflection appears 16 meters away.

  • In the third section of the maze, no combination of integer distances will cause the second reflection to appear 5 meters away.

  • In the fourth section of the maze, the first reflection appears 4 meters away and the second reflection appears 10 meters away.

Sample Input 1 Sample Output 1
4
1 6
3 16
2 5
2 10
3 1
1 6
impossible
2 3

Please log in to submit a solution to this problem

Log in