Consider a construction site in the shape of a coordinate grid. Multiple roads exist on lines parallel to the x-axis or y-axis. This grid of roads expands infinitely in all directions. Multiple trucks, up to 1000, are stationed a various intersections. All the trucks are described as a x and y coordinate, and each one has a unique x-coordinate and y-coordinate from the rest. All coordinates are nonnegative integers. The trucks are also positioned facing towards the north (that is, upwards on the y-axis) or facing towards the east (that is, facing to the right on the x-axis). More specifically, if a truck is positioned north and moves, it will move from (x,y) to (x,y+1). If it had instead moved east, it would have moved from (x,y) to (x+1,y). Once a signal is given to all trucks simultaneously, they start moving in their respective direction and pour concrete behind them. If a truck ever encounters an intersection where another truck has already poured concrete, it stops. Please determine the amount of units each truck will have moved. If a truck will continue to pour concrete to infinity, print "infinity". INPUT FORMAT: In the first line, you are given a number N representing the total number of trucks. Following this, you are given the input of the ith truck. The input goes as follows. It starts with either the letter N or E, representing the direction the truck is orientated. Next, it will have the x-coordinate and then y-coordinate. OUTPUT FORMAT: Print N different lines, each with the amount of units each truck travels. If the truck does not ever stop, print "Infinity". SAMPLE INPUT: 6 E 3 5 N 5 3 E 4 6 E 10 4 N 11 2 N 8 1 SAMPLE OUTPUT: 5 3 Infinity Infinity 2 5 |
5 ..E....... 4 .......... 3 .......... 2 .......... 1 .......N.. 0 .......... 0123456789 |
5 ..E....... 4 .......... 3 ......e... 2 .......... 1 .......N.. 0 .......... 0123456789 |