Tanks

Trace a shot through a convex hull and inner boxes, applying face resistance and ricochets, and report pierced components and where it stops.

Medium7GeometrySimulationNo attempts yetTime limit1sMemory limit256 MB

Problem

A tank hull is a convex polyhedron. Several crucial components sit inside it, and each component is a box whose sides are parallel to the coordinate axes. The components are pairwise disjoint, lie strictly inside the hull, and touch neither one another nor the hull.

A shot is given by an origin point, a direction vector and an initial speed. The origin lies strictly outside the hull. The shot travels along a straight line and keeps its speed while it flies.

Every face of the hull and every face of a component has a resistance rr and a deflection threshold tt. The six faces of one component have the same resistance and the same deflection threshold. When the shot reaches a face, its speed drops by the resistance of that face. If the speed after the drop is at most the deflection threshold of that face, the shot ricochets off the face, and the angle of reflection equals the angle of incidence. Otherwise the shot pierces the face and flies on in the same direction. The shot can ricochet more than once.

The shot disintegrates the moment its speed drops to 0 or below, and it also disintegrates the moment the number of faces it has pierced or deflected off reaches DD. In both cases it disintegrates at the point where it met that last face, and it reaches no further face afterwards.

A component counts as pierced only if the shot travels strictly inside it. A ricochet off a face of a component is not a piercing.

The shot never comes closer than 10 to any edge or vertex of a face of the hull or of a component, and it never passes through a face while moving parallel to that face.

Report which components the shot pierces and where it disintegrates.

Input

The first line has one integer TT, the number of test cases. Each test case is given as follows.

The first line has two integers FF and CC (4F10004 \le F \le 1000, 0C1000 \le C \le 100), the number of faces of the hull and the number of crucial components.

The second line has two integers DD and SS (1D1001 \le D \le 100, 1S10000001 \le S \le 1000000), the limit on the number of faces the shot pierces or deflects off, and the initial speed of the shot.

The third line has six integers aa, bb, cc, dd, ee, ff (1000000a,b,c,d,e,f1000000-1000000 \le a, b, c, d, e, f \le 1000000). The point (a,b,c)(a, b, c) is the origin of the shot and (d,e,f)(d, e, f) is its direction vector.

The FF faces of the hull follow. Each face starts with a line holding three integers vv, rr and tt (3vF3 \le v \le F, 0r,t10000000 \le r, t \le 1000000), the number of vertices of the face, its resistance and its deflection threshold. The next vv lines hold three integers xx, yy and zz each (1000000x,y,z1000000-1000000 \le x, y, z \le 1000000), the vertices of the face in order along its boundary. No three consecutive vertices of a face lie on one line.

After the FF faces come CC lines, one per crucial component. Each of them holds eight integers xx, yy, zz, xsx_s, ysy_s, zsz_s, rr and tt (1000000x,y,z1000000-1000000 \le x, y, z \le 1000000, 1xs,ys,zs10000001 \le x_s, y_s, z_s \le 1000000, 0r,t10000000 \le r, t \le 1000000). The point (x,y,z)(x, y, z) is the center of the box, xsx_s, ysy_s and zsz_s are its side lengths along the three axes, rr is the resistance of each of its six faces and tt is the deflection threshold of each of its six faces.

Integers on one line are separated by single spaces.

Output

Print the following for each test case.

First a line with CpC_p, the number of components the shot pierces. Then CpC_p lines, each holding the 0-based index of one pierced component, in increasing order.

Then one more line with three integers separated by single spaces, the point where the shot disintegrated, with every coordinate rounded down to the nearest integer. Every such coordinate is either an integer that already appears in the input, or it is far enough from an integer that the rounding is unambiguous. If the shot never disintegrates, print SHOT NEVER DISINTEGRATED on that line instead.