Under construction

Still being built. Things may change

Ghost

Time limit10sMemory limit512 MB

Summary
Given axis-aligned rectangles that move at constant speeds, answer each query by reporting the maximum area common to all rectangles during a time interval [l, r].
Level

Hard9 of 10

Topics
Geometry, Sorting, Binary search
Solved
No attempts yet

Problem

Your team has been trapped in an ancient chamber at Wawel Castle in Kraków by the Ghost. He will not let you out unless you answer his questions.

On the wall there are nn paintings. If we treat the wall as the standard Euclidean plane, each painting is an axis-aligned rectangle. For every painting you know its exact dimensions and starting position. At moment 0, the Ghost starts moving the paintings, each one in its own direction and speed. You are an observant team, so you can work out the exact speed of every painting.

After some time, the Ghost stops the show and starts asking tough questions. Each question gives two numbers ll and rr, which are moments of the show. You must tell the Ghost whether there was a moment between ll and rr when some spot on the wall was covered by all the paintings at once. If so, you must also find the maximum possible common area of all paintings between moments ll and rr.

If you ever want to leave this room, give the Ghost the right answers.

Input

The first line contains the number of test cases zz (1≤z≤40001 \le z \le 4000). Each test case has the following format.

The first line of a test case contains the number of paintings nn (1≤n≤1000001 \le n \le 100000). Each of the next nn lines contains six numbers x1,y1,x2,y2,vx,vyx_1, y_1, x_2, y_2, v_x, v_y (−1000000≤x1<x2≤1000000-1000000 \le x_1 < x_2 \le 1000000; −1000000≤y1<y2≤1000000-1000000 \le y_1 < y_2 \le 1000000; −1000000≤vx,vy≤1000000-1000000 \le v_x, v_y \le 1000000), where (x1,y1)(x_1, y_1) is the lower left corner of the painting, (x2,y2)(x_2, y_2) is its upper right corner, and (vx,vy)(v_x, v_y) is its speed vector. At moment tt, the lower left corner is at (x1+tvx,y1+tvy)(x_1 + t v_x, y_1 + t v_y) and the upper right corner is at (x2+tvx,y2+tvy)(x_2 + t v_x, y_2 + t v_y).

The next line contains the number of Ghost's questions qq (1≤q≤1000001 \le q \le 100000). Each of the next qq lines contains two real numbers ll and rr (0≤l≤r≤10000000 \le l \le r \le 1000000) with at most 4 decimal places, which denote the closed time interval [l,r][l, r].

The total number of paintings across all test cases does not exceed 1000000. The total number of questions across all test cases does not exceed 1000000.

Output

For each question, print one real number: the maximum area of the intersection of all paintings during the interval [l,r][l, r]. Your answer is accepted if the absolute or relative error is at most 10−610^{-6}. That is, if your output is aa and the correct value is bb, it is accepted when ∣a−b∣/max⁡(1,b)≤10−6|a-b|/\max(1, b) \le 10^{-6}. If the intersection is empty, print 0 (an error of ±10−6\pm 10^{-6} is allowed).

Examples1

  1. Example 1

    Input
    2
    2
    0 0 1 1 1 1
    1 1 2 2 -1 -1
    3
    0 0
    0.25 0.25
    0 2
    3
    0 0 1 1 2 2
    0 0 1 1 1 1
    1 1 2 2 -1 -1
    1
    0 2
    
    Expected output
    0.000000000
    0.250000000
    1.000000000
    0.444444444