## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Saving the Jelly Solution Round 2 2022 - Code Jam 2022

### Problem

Mr. Jolly teaches football (or soccer, for US speakers) to $N$ children numbered from $1$ to $N$. He has taken to leaving sweets on the field where the games take place, one for each child. After the game is finished, each child can grab and eat one sweet as their reward.

The children are tired after games, so each child wants to grab the sweet closest to them. This could lead to fights — if the same sweet is closest to two or more children. To avoid that, after the game all the children stop where they are, and Mr. Jolly calls out their names, one by one. When a child's name is

called, they grab the closest sweet to them (out of the ones that weren't already grabbed, of course). In the case where two or more sweets are tied for the smallest distance, Mr. Jolly can decide which one the child grabs. This has worked very well for Mr. Jolly for a while now, but today disaster struck! While laying out the sweets, Mr. Jolly accidentally dropped his blueberry jelly that he planned to eat after all the children go home. So now there are $N$ children on the field, and $\mathbf{N}+1$ sweets. The sweets are numbered from $1$ to $N$, with sweet $1$ being Mr. Jolly's blueberry jelly. Is there a way for Mr. Jolly to save his blueberry jelly by calling the children's names in such an order that the blueberry jelly is the one sweet left over?

### Input

The first line of the input gives the number of test cases, $T$$T$ test cases follow. Each test begins with a line containing a single integer, $N$, the number of children on the field. The next $N$ lines describe the positions of the children. Each of these lines contains two integers, ${\mathbf{X}}_{\mathbf{i}}$ and ${\mathbf{Y}}_{\mathbf{i}}$, representing the position of the $i$⁠-th child after the game ends. Then there are $\mathbf{N}+1$ more lines that describe the positions of sweets after the game, where the first of the sweets is Mr. Jolly's blueberry jelly. Each of these lines contains two integers, ${\mathbf{X}}_{\mathbf{j}}$ and ${\mathbf{Y}}_{\mathbf{j}}$, representing the position of the $j$⁠-th sweet.

### Output

For each test case, output one line containing Case #x$x$: y$y$, where $x$ is the test case number (starting from 1) and $y$ is IMPOSSIBLE if there is no way Mr. Jolly can choose the children (and break ties for the closest sweet) to leave his blueberry jelly uneaten. Otherwise, if Mr. Jolly can save his blueberry jelly, $y$ is POSSIBLE. If Mr. Jolly can save his jelly, output $N$ additional lines representing the order the children will go and which jellies they will pick. The $i$⁠-th line should contain two integers ${A}_{i}$ and ${B}_{i}$ representing that child ${A}_{i}$ will go next and will pick sweet ${B}_{i}$. The sweet ${B}_{i}$ must be the closest (or tied for the closest) sweet to child ${A}_{i}$ when they go to pick their sweet.

### Limits

Memory limit: 1 GB.
$1\le \mathbf{T}\le 100$.
$-{10}^{9}\le {\mathbf{X}}_{\mathbf{i}}\le {10}^{9}$, for all $i$.
$-{10}^{9}\le {\mathbf{Y}}_{\mathbf{i}}\le {10}^{9}$, for all $i$.
$-{10}^{9}\le {\mathbf{X}}_{\mathbf{j}}\le {10}^{9}$, for all $j$.
$-{10}^{9}\le {\mathbf{Y}}_{\mathbf{j}}\le {10}^{9}$, for all $j$.

#### Test Set 1 (Visible Verdict)

Time limit: 10 seconds.
$1\le \mathbf{N}\le 10$.

#### Test Set 2 (Hidden Verdict)

Time limit: 45 seconds.
$1\le \mathbf{N}\le 1000$.