Polygon and Lines

For each line crossing a convex polygon, find the closest polygon vertex to the line and print the distance.

Medium7GeometryBinary searchNo attempts yetTime limit0.5sMemory limit128 MB

Problem

Gustav likes to solve geometry problems. While browsing geometry problems on the internet he ran into one he could not solve on his own, so help him solve the following problem.

You are given one convex polygon and several lines that cross it. For each line, find the vertex of the polygon closest to that line and compute the distance between the line and that vertex.

A line crosses the polygon if it has at least one point in common with the interior of the polygon.

Input

The first line contains the number of vertices of the polygon NN (3N1000003 \le N \le 100\,000).

Each of the next NN lines holds the coordinates of one vertex of the convex polygon: two integers whose absolute value is smaller than 10910^9. The vertices are given in clockwise order.

The next line contains the number of lines MM (1M1000001 \le M \le 100\,000).

Each of the next MM lines holds three integers AA, BB, CC that describe the line Ax+By+C=0Ax + By + C = 0. Here A,B,C109|A|, |B|, |C| \le 10^9, and AA and BB are never both 00. Every given line crosses the polygon.

Output

Print MM lines. Line ii holds the distance between line ii and the closest vertex of the polygon, rounded to three decimal places.