Irregular Cakes (Large Input)

Find the vertical cut positions that split the region between two polylines into G slices of equal area.

Medium5GeometryBinary searchPrefix sumNo attempts yetTime limit5sMemory limit512 MB

Problem

Mary the mathematician opened a bakery a few years ago. She has grown tired of baking the same rectangular and circular cakes all this time, so for her next birthday she wants to bake an irregular cake, which is the region between two polylines that run from x=0x=0 to x=Wx=W. The lower polyline is the lower boundary and the upper polyline is the upper boundary.

The lower boundary and the upper boundary of an irregular cake

A polyline is defined by a sequence of points (P0,P1,,Pn)(P_0, P_1, \ldots, P_n) listed from left to right. Joining each pair of neighboring points with a line segment produces the polyline.

Today is Mary's birthday. She has baked an irregular cake bounded by a lower boundary with LL points and an upper boundary with UU points. After the birthday song she wants to make G1G-1 vertical cuts that split the cake into GG slices of equal area, so every guest gets one slice. The irregular shape makes the cut positions hard to work out. Find where Mary has to cut.

Input

The first line contains the number of test cases TT. TT test cases follow.

The first line of each test case contains four integers WW, LL, UU and GG separated by spaces. WW is the width of the cake, LL is the number of points on the lower boundary, UU is the number of points on the upper boundary, and GG is the number of guests at the party.

The next LL lines give the lower boundary. The ii-th of them contains the coordinates xix_i and yiy_i of the ii-th point on the lower boundary. The next UU lines give the upper boundary in the same format.

Limits

  • 1T1001 \le T \le 100
  • 1W10001 \le W \le 1000
  • 2L1002 \le L \le 100
  • 2U1002 \le U \le 100
  • 2G1012 \le G \le 101
  • Every coordinate is an integer between 1000-1000 and 10001000, inclusive.
  • On both boundaries the leftmost point has xx-coordinate 00 and the rightmost point has xx-coordinate WW.
  • Points on the same boundary are given in increasing order of xx-coordinate, and their xx-coordinates are distinct.
  • For every xx with 0xW0 \le x \le W, the yy-coordinate of the lower boundary is smaller than the yy-coordinate of the upper boundary.

Output

For each test case, print GG lines. The first line is Case #x:, where xx is the test case number starting from 11. The next G1G-1 lines contain the xx-coordinates of the cuts, one per line, ordered from the leftmost cut to the rightmost cut.

The height of the cake is positive on the whole interval 0xW0 \le x \le W, so the area accumulated from the left increases strictly with xx. Each cut position is therefore unique.

Round every coordinate to six digits after the decimal point, rounding a half up, and print all six digits. If the exact value is 55, print 5.000000.