The Slowest Speed Past the Traps

Find the minimum constant running speed that lets Fred cross every trap during an inactive window, or report IMPOSSIBLE.

Medium7Binary searchMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Fred is escaping from an underground prison. He has already reached the outer corridor, and all that is left is a straight run to the exit door. The trouble is that the corridor is lined with traps. A trap works like a magnet, so Fred is held in place if he is inside the trap area while the trap is active. Standing exactly on the edge of a trap is safe.

Capturing a runner costs a trap a lot of energy, so a trap stays on only briefly. Each trap is active for AA seconds, then inactive for BB seconds, and repeats that cycle forever. Fred starts at position 0 at time 0, and every trap begins its cycle in the active state at that same moment.

Fred runs at one constant speed vv. If a trap covers the segment [S1,S2][S_1, S_2], Fred touches its near edge at time S1/vS_1/v and leaves its far edge at time S2/vS_2/v. He passes that trap safely only if some nonnegative integer kk satisfies

k(A+B)+AS1v,S2v(k+1)(A+B)k(A+B) + A \le \frac{S_1}{v}, \qquad \frac{S_2}{v} \le (k+1)(A+B)

so that he both enters and leaves during a single inactive window of that trap.

Find the slowest speed that carries Fred safely past every trap.

Input

The first line has the number of test cases TT. (0<T100 < T \le 10)

The first line of each test case has the number of traps NN. (0<N300 < N \le 30)

Each of the next NN lines describes one trap as AA BB S1S_1 S2S_2.

  • AA is how long the trap stays active, in seconds. (0<A<327680 < A < 32768)
  • BB is how long the trap stays inactive, in seconds. (0<B<327680 < B < 32768)
  • S1S_1 is where the trap starts, in meters from the starting point.
  • S2S_2 is where the trap ends, in meters from the starting point. (0<S1<S2<327680 < S_1 < S_2 < 32768)

All values are integers. Segments of different traps may overlap.

Output

Print one line for each test case.

If a safe speed exists, print the slowest one in meters per second with four digits after the decimal point. Round at the fifth digit, and round up when that digit is exactly 5. If no such speed exists, print IMPOSSIBLE.

Hint

Take a corridor with a single trap where A=3A = 3, B=1B = 1, S1=2S_1 = 2 and S2=3S_2 = 3.

The trap is inactive for only 1 second, so Fred has to cover the stretch from 2 meters to 3 meters within 1 second, which means his speed cannot be below 1 meter per second. The trap first turns off at second 3, so reaching the 2 meter mark before second 3 gets him caught, which means his speed cannot be above 2/32/3 meter per second. No speed satisfies both conditions, so the answer is IMPOSSIBLE.