Connected Gheeves#5043

Connected Gheeves

1 second
64 megabytes
Hard

Gheeves (plural of gheef) are objects similar to funnels. We define a gheef as a two-dimensional object specified by a sequence of points p_1, p_2, \ldots, p_n with the following properties:

For example, the following figure shows a gheef with six points and c = 4:

We call the sequence of segments p_1p_2, p_2p_3, \ldots, p_{n-1}p_n the body of the gheef. In this problem, you are given two gheeves P = (p_1, p_2, \ldots, p_n) and Q = (q_1, q_2, \ldots, q_m), such that all -coordinates of p_i are negative integers, and all -coordinates of q_i are positive integers.

Assume the cusps of the two gheeves are connected by a narrow pipe. Water is poured into the gheeves; as water is poured, the gheeves fill upwards according to basic physical laws (the water level in both gheeves remains the same). When the water level in gheef reaches \min(y_1, y_n), water will begin to spill out of (the same holds for ).

You must determine the final water level in the gheeves after a specified amount of water has been poured. Since the problem is considered in two dimensions, the amount of water is measured by the area it fills. Assume the volume of the connecting pipe is zero.

Input

The first line contains the number of test cases . Each test case consists of three lines. The first of these three lines contains an integer (1 \leq a \leq 100000), the amount of water poured into the two gheeves. The next two lines describe and . Each gheef is specified as x_1 y_1 x_2 y_2 \ldots x_k y_k, where is the number of points in the gheef ( for and for ), and the x_i, y_i pairs are the coordinates of the points of the gheef in sequence.

Output

Print lines, one for each test case. Each line should contain a single number —the final water level, as a real number in units of the coordinate, rounded to three decimal places.

Examples

Example 1

Loading
Loading