Planet Destruction

Each of K rockets hits the circle at an angle, and each virus spreads both ways along the circle at its own speed; find the first time every point of the circumference is covered.

Medium7Binary searchIntervalsGeometryMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Darth Vader is back to his favourite hobby, destroying planets, or to be precise their population. He has learned that the rebel leadership gathered on a planet named Watooine, so he wants to remove the threat quickly. The Empire is in a deep recession and no Death Star is left, so his plan is to drop several containers of a deadly virus onto the surface of the planet.

The problem is modelled in two dimensions. Watooine is a circle of radius RR centred at (0,0)(0, 0). KK Empire spaceships each launch one rocket at the same moment, and every rocket flies in a straight line towards (0,0)(0, 0) at the speed of its own ship. A rocket stops the instant it touches the surface. From the point of impact a virus starts spreading along the surface, moving clockwise and counterclockwise at the same rate. Each virus has its own spread speed. A virus travels only along the surface, so it never crosses the interior of the planet to reach the other side.

The planet is completely infected once every point of the surface has been reached by at least one virus. Find how long that takes.

Input

The first line contains TT, the number of test cases. Each test case is given as follows. The first line has two integers RR, the radius of the planet in meters, and KK, the number of spaceships. Each of the next KK lines has four integers: the x coordinate of the ship, the y coordinate of the ship, the speed of its rocket, and the spread speed of its virus. Both speeds are given in meters per second, and the spread speed is measured along the surface. No ship lies inside the planet.

1T1001 \le T \le 100, 1R10000001 \le R \le 1000000, 1K100001 \le K \le 10000, both coordinates are between 1000000-1000000 and 10000001000000, and both speeds are between 11 and 10000001000000.

Output

For each test case, print one line with the number of seconds until the planet is completely infected, rounded to exactly four digits after the decimal point.