The Worm in the Apple

No attempts yetTime limit15sMemory limit128 MB

Problem

Willy the Worm was living happily inside an apple — until a human picked the apple and started to eat it! Now Willy must escape.

You are given a description of the apple as a convex solid in 3D space, together with several positions inside the apple where Willy might be. For each position, determine the minimum distance Willy must travel to reach the surface of the apple.

Input

The input contains several test cases.

Each test case begins with a line containing a single integer $n$ ($4 \le n \le 1000$), the number of points that describe the apple.

Each of the next $n$ lines contains three integers $x$, $y$, $z$ ($-10000 \le x, y, z \le 10000$); the point $(x, y, z)$ lies on the surface of, or inside, the apple. The apple is the convex hull of these $n$ points, and no four of the points are coplanar.

The next line contains a single integer $q$ ($1 \le q \le 100000$), the number of query positions. Each of the following $q$ lines contains three integers $x$, $y$, $z$ ($-10000 \le x, y, z \le 10000$), a position $(x, y, z)$ where Willy might be. Every query position is guaranteed to lie inside the apple.

The input ends with a line containing a single $0$.

Output

For each query, output on its own line the minimum distance Willy must travel to reach the surface of the apple. Print the value with exactly 4 digits after the decimal point, using round-half-up rounding (a next digit of 5 or more rounds up, 4 or less rounds down); for example $2.12344$ becomes $2.1234$ and $2.12345$ becomes $2.1235$. Print no extra spaces and no blank lines between answers.