Problem
Some pranksters have watched too much Discovery Channel and now they want to build a crop triangle during the night. They want to build it inside a large crop that looks like an evenly spaced grid from above. There are some trees planted on the field. Each tree is situated on an intersection of two grid lines (a grid point). The pranksters want the vertices of their crop triangle to be located at these trees. Also, for their crop triangle to be more interesting they want the center of that triangle to be located at some grid point as well. We remind you that if a triangle has the vertices (x_{1}, y_{1}), (x_{2}, y_{2}) and (x_{3}, y_{3}), then the center for this triangle will have the coordinates ((x_{1} + x_{2} + x_{3}) / 3, (y_{1} + y_{2} + y_{3}) / 3).
You will be given a set of points with integer coordinates giving the location of all the trees on the grid. You are asked to compute how many triangles you can form with distinct vertexes in this set of points so that their center is a grid point as well (i.e. the center has integer coordinates).
If a triangle has area 0 we will still consider it a valid triangle.
Input
The first line of input gives the number of cases, N. N test cases follow. Each test case consists of one line containing the integers n, A, B, C, D, x_{0}, y_{0} and M separated by exactly one space. n will be the number of trees in the input set. Using the numbers n, A, B, C, D, x_{0}, y_{0} and M the following pseudocode will print the coordinates of the trees in the input set. mod indicates the remainder operation.
The parameters will be chosen such that the input set of trees will not have duplicates.
X = x_{0}, Y = y_{0}
print X, Y
for i = 1 to n1
X = (A * X + B) mod M
Y = (C * Y + D) mod M
print X, Y
Output
For each test case, output one line containing "Case #X: " where X is the test case number (starting from 1). This should be followed by an integer indicating the number of triangles which can be located at 3 distinct trees and has a center that is a grid point.
Limits
1 <= N <= 10,
0 <= A, B, C, D, x_{0}, y_{0}<= 10^{9},
1 <= M <= 10^{9}.
Small dataset
3 <= n <= 100.
Large dataset
3 <= n <= 100000.
Sample
Input 
Output 
2

Case #1: 1

In the first test case, the 4 trees in the generated input set are (0, 1), (7, 3), (17, 5), (17, 7).