There's a really sad story.It could be about love or about money.But love will vanish and money will be corroded.These points will last forever.So this time it is about points on a plane.
We have a plane that has no points at the start.
And at the time i,we add point p
i(x
i, y
i).There is n points in total.
Every time after we add a point,we should output the square of the distance between the closest pair on the plane if there's more than one point on the plane.
As there is still some love in the problem setter's heart.The data of this problem is randomly generated.
To generate a sequence x
1, x
2, ..., x
n,we let x
0 = 0,and give you 3 parameters:A,B,C. Then x
i = (x
i-1 * A + B) mod C.
The parameters are chosen randomly.
To avoid large output,you simply need output the sum of all answer in one line.
The first line contains integer T.denoting the number of the test cases.
Then each T line contains 7 integers:n A
x B
x C
x A
y B
y C
y.
A
x,B
x,C
x is the given parameters for x
1, ..., x
n.
A
y,B
y,C
y is the given parameters for y
1, ..., y
n.
T <= 10.
n <= 5 * 10
5.
10
4 <= A,B,C <= 10
6.
For each test cases,print the answer in a line.