Omnicircumnavigation (Large)

Given points on a unit sphere joined in order by shortest arcs, decide whether the closed path meets every great circle.

Hard9GeometryMathImplementationBrute forceNo attempts yetTime limit120sMemory limit512 MB

Problem

K travels a lot. On one recent trip she went from San Francisco to Frankfurt to Johannesburg to Abu Dhabi to Singapore to Tokyo and back to San Francisco. On that trip she circumnavigated the Earth along a closed path that touches every meridian. For every possible longitude there is at least one point of the path at that longitude.

K is not sure that such a trip deserves much credit, since flying to the North Pole and then walking around it would also count. So she came up with a more general definition. An omnicircumnavigation is a closed path around the Earth, which we assume to be a sphere, that is a circumnavigation no matter where the poles are placed. In other words, an omnicircumnavigation is a closed path on the surface of a sphere that touches every possible hemisphere. Touching the edge of a hemisphere is enough. Stated another way, an omnicircumnavigation intersects every possible great circle, a circle of greatest possible diameter on the surface of a sphere.

You are given a sequence of NN points on a sphere of radius 1. Decide whether the path that connects those points in order is an omnicircumnavigation. The path connects each pair of successive points along the shortest surface route, and connects the last point to the first one in the same way. No two successive points, including the pair formed by the last point and the first point, are collinear with the origin. They are not antipodes, and they do not represent the same point on the surface of the sphere.

Input

The first line of the input gives the number of test cases, TT. The first line of each test case contains NN, the number of places K visited. Each of the next NN lines contains three integers XiX_i, YiY_i and ZiZ_i. The ii-th point in the list is the point (XiXi2+Yi2+Zi2,YiXi2+Yi2+Zi2,ZiXi2+Yi2+Zi2)\left(\dfrac{X_i}{\sqrt{X_i^2 + Y_i^2 + Z_i^2}}, \dfrac{Y_i}{\sqrt{X_i^2 + Y_i^2 + Z_i^2}}, \dfrac{Z_i}{\sqrt{X_i^2 + Y_i^2 + Z_i^2}}\right) on the sphere.

Limits

  • 1T2001 \le T \le 200
  • 3N50003 \le N \le 5000
  • 106Xi106-10^6 \le X_i \le 10^6 for all ii
  • 106Yi106-10^6 \le Y_i \le 10^6 for all ii
  • 106Zi106-10^6 \le Z_i \le 10^6 for all ii
  • At least one of XiX_i, YiY_i, ZiZ_i is nonzero, for all ii.
  • For two successive points on the path, neither one is a constant multiple of the other. The last point and the first point count as successive. That is, two successive points are never antipodes and never the same point on the sphere.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number and yy is YES if the route is an omnicircumnavigation and NO if it is not.

Notes

In the first test case of the example input, the three points are the corners of one octant of the sphere, and the path traces the border of that octant. Many hemispheres do not meet that path at all.

In the second test case, the eight points are the corners of a cube inscribed in the sphere. Every hemisphere contains some part of that path. Dividing all values by 5 produces the same set of points, so the answer stays the same.

In the third test case, the path is itself a great circle, so every other great circle meets it somewhere.

The fourth test case uses the same three points as the third one, except that the first two points are visited twice each. A test case may list the same point more than once, and a path may cover the same points or the same arcs more than once.