Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3849
You need Medicine

Time Limit: 3 Seconds      Memory Limit: 65536 KB      Special Judge

There are too many sick people in the world, and it is our duty to provide them with some medicine. In order to meet people's needs, Old Military Surgeon produced a lot of pills. But the pills work only when they are spinning about a fixed axis of rotation. This is because spinning gives the pills happiness. The happiness of the pill is the moment of inertia about the fixed axis of rotation. For every differential element of the pill, the differential element of the happiness is the differential element of the volume multiplied by the square of the distance between it and the fixed axis of rotation. Now we have an cuboid pill whose edges are all parallel to the coordinate axes. And the axis is through the origin point. It is your task to calculate the amount of happiness given by spinning. But wait, don't be too haste to calculate, as Old Military Surgeon wants some medicine himself, he can scoop out any cuboid part from the pill, and the scooped cuboid is also parallel to the coordinate axes. Now your task is to calculate the happiness of the pill after Old Military Surgeon's scooping.

Input

There are multiple test cases. The first line contains the Number of cases T. For each case the first line contains six integers X0, Y0, Z0, X1, Y1, Z1 which are the coordinate of the lower left corner and the upper right corner of the original pill.

The second line contains three integers Sx, Sy, Sz, which shows the direction vector of the axis of rotation.

The third line contain a integer N (0 ≤ N≤ 100) which is the number of the cuboids scooped out by Old Military Surgeon. For the next N lines, each line contains six integers six integers x0, y0, z0, x1, y1, z1, which are the coordinates of the lower left corner and the upper right corner of a scooped cuboid. The absolute of all the integers given by the input will be no more than 1000.

Output

For each case, output the happiness of the pill after Old Military Surgeon's scooping. Absolute or relative error no more than 1e-6 will be accepted.

Sample Input

1
-2 -2 -2 0 0 0
0 0 1
2
-1 -1 -1 0 0 0
-2 -1 -2 0 0 0

Sample Output

14.6666666667

Author: ZHU, Heming
Source: ZOJ Monthly, January 2015
Submit    Status