Landing slots

For each incoming aircraft, find the lowest free landing slot it can physically reach and report the join point and arrival time.

Medium7GeometrySimulationBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

The airport control area is a circle of radius RR km. The runway lies north of the centre, and the landing path is the straight line running south from the centre.

Think of the landing path as a huge conveyor belt in the sky. At midnight slot 0 sits at the centre, and slots 1, 2, and onward follow it to the south, each one 30 seconds of flying time behind the one before. Every aircraft flies at 400 km/h, so neighbouring slots are 103\frac{10}{3} km apart. The belt moves north at 400 km/h, so tt hours after midnight slot kk sits 10k3400t\frac{10k}{3} - 400t km south of the centre. At 1am slot 120 is exactly at the centre.

Aircraft come in from far away, flying straight at the centre. Aircraft ii reaches the edge of the control area tit_i hours after midnight on heading bib_i degrees. A heading is measured clockwise from north, so a negative heading points west of north. No aircraft flies due north or due south.

An aircraft is given a slot the moment it reaches the edge. It turns once, flies straight at 400 km/h to the point where it meets that slot exactly, then turns onto the landing path and rides the belt to the centre. An aircraft may use a slot only when it meets the slot south of the centre and no more than RR km from the centre, so the meeting point lies on the landing path inside the control area.

Take R=23R = 23 and an aircraft arriving at 1am on heading -50. The lowest slot it can meet is 127. Turning left by a larger angle each time lets it meet 128, 129, and so on up to 132. Slot 133 is out of reach, because the meeting point would fall outside the control area.

Aircraft are processed in the order the control system receives them. Each aircraft takes the lowest numbered slot it can meet that no earlier aircraft in the same scenario has taken. The allocation does not check whether flight paths cross, because another part of the system does that.

Input

The first line holds the number of scenarios PP.

Each scenario begins with a line holding two integers: the radius RR (10R10010 \le R \le 100) of the control area in km, and the number of aircraft NN (1N301 \le N \le 30). The next NN lines describe the aircraft in the order the control system receives them. Each of those lines holds the arrival time tit_i (0ti200 \le t_i \le 20) at the edge of the control area, given in hours after midnight with exactly four decimal places, then the integer heading bib_i in degrees, which satisfies 90bi10-90 \le b_i \le -10 or 10bi9010 \le b_i \le 90.

Within one scenario the arrival times do not decrease. Values on a line are separated by single spaces, with no leading or trailing spaces. Every aircraft has at least one slot available.

Output

For each scenario, print a line holding Scenario and the scenario number, counting from 1. Then print one line per aircraft, in the order the aircraft were given:

Slot k, joining at Dkm south, final approach at T

kk is the allocated slot number, DD is the distance in km from the centre to the point where the aircraft joins the landing path, and TT is the time in hours after midnight at which the aircraft reaches the centre. Print DD and TT rounded to exactly four decimal places. No value in the data sits on a rounding boundary.