MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (
AiAi+
AjAj)(
1≤i,j≤n1≤i,j≤n)
The xor of an array B is defined as B1B1 xor B2B2...xor BnBn
InputMultiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
The xor of an array B is defined as B1B1 xor B2B2...xor BnBn
Each test case contains four integers: nn, mm, zz, ll
A1=0A1=0, Ai=(Ai−1∗m+z)Ai=(Ai−1∗m+z) modmod ll
1≤m,z,l≤5∗1051≤m,z,l≤5∗105, n=5∗105n=5∗105
OutputFor every test.print the answer.Sample Input
2 3 5 5 7 6 8 8 9Sample Output
14 16
这题的关键是你要注意到明白xi+xj和xj+xi是不一样的,所以结果就是相同数之和xi+xi之间异或的结果,结果怕溢出就用long long