406641: GYM102470 F Haunted Graveyard
Description
Tonight is Halloween and Scared John and his friends have decided to do something fun to celebrate the occasion: crossing the graveyard. Although Scared John does not find this fun at all, he finally agreed to join them in their adventure. Once at the entrance, the friends have begun to cross the graveyard one by one, and now it is the time for Scared John. He still remembers the tales his grandmother told him when he was a child. She told him that, on Halloween night, "haunted holes" appear in the graveyard. These are not usual holes, but they transport people who fall inside to some point in the graveyard, possibly far away. But the scariest feature of these holes is that they allow one to travel in time as well as in space; i.e., if you fall inside a "haunted hole", you appear somewhere in the graveyard a certain time before (or after) you entered the hole, in a parallel universe otherwise identical to ours.
The graveyard is organized as a grid of $$$W \times H$$$ cells, with the entrance in the cell at position $$$(0, 0)$$$ and the exit at $$$(W - 1, H - 1)$$$. Despite the darkness, Scared John can always recognize the exit, and he will leave as soon as he reaches it, determined never to set foot anywhere in the graveyard again. On his way to the exit, he can walk from one cell to an adjacent one, and he can only head to the North, East, SouthWest. In each cell there can be either one gravestone, one "haunted hole", or grass:
- If the cell contains a gravestone, you cannot walk over it, because gravestones are too high to climb.
- If the cell contains a "haunted hole" and you walk over it, you will appear somewhere in the graveyard at a possibly different moment in time. The time difference depends on the particular "haunted hole" you fell into and can be positive, negative or zero.
- Otherwise, the cell has only grass, and you can walk freely over it.
The input consists of several test cases. Each test case begins with a line containing two integers $$$W$$$ and $$$H$$$ ($$$1 \le W, H \le 30$$$). These integers represent the width $$$W$$$ and height $$$H$$$ of the graveyard. The next line contains an integer $$$G$$$ ($$$G \ge 0$$$), the number of gravestones in the graveyard, and is followed by $$$G$$$ lines containing the positions of the gravestones. Each position is given by two integers $$$X$$$ and $$$Y$$$ ($$$0 \le X < W$$$ and $$$0 \le Y < H$$$).
The next line contains an integer $$$E$$$ ($$$E \ge 0$$$), the number of "haunted holes", and is followed by $$$E$$$ lines. Each of these contains five integers $$$X_1$$$, $$$Y_1$$$, $$$X_2$$$, $$$Y_2$$$, $$$T$$$. $$$(X_1, Y_1)$$$ is the position of the "haunted hole" ($$$0 \le X_1 < W$$$ and $$$0 \le Y_1 < H)$$$. $$$(X_2, Y_2)$$$ is the destination of the "haunted hole" ($$$0 \le X_2 < W$$$ and $$$0 \le Y_2 < H$$$). Note that the origin and the destination of a "haunted hole" can be identical. $$$T$$$ ($$$-10 000 \le T \le 10 000$$$) is the difference in seconds between the moment somebody enters the "haunted hole" and the moment he appears in the destination position; a positive number indicates that he reaches the destination after entering the hole. You can safely assume that there are no two "haunted holes" with the same origin, and the destination cell of a "haunted hole" does not contain a gravestone. Furthermore, there are neither gravestones nor "haunted holes" at positions $$$(0,0)$$$ and $$$(W-1,H-1)$$$.
The input will finish with a line containing 0 0, which should not be processed.
OutputFor each test case, if it is possible for Scared John to travel back in time indefinitely, output Never. Otherwise, print the minimum time in seconds that it takes him to cross the graveyard from the entrance to the exit if it is reachable, and Impossible if not.
ExampleInput3 3 2 2 1 1 2 0 4 3 2 2 1 3 1 1 3 0 2 2 0 4 2 0 1 2 0 1 0 -3 0 0Output
Impossible 4 Never