There are multiple test cases. The first line of input contains an integer $T$ $(1 \le T \le 10^4)$, indicating the number of test cases. For each test case:
The first line contains five integers $n$, $p$, $b_0$, $A$, $B$ $(1 \le n \le 10^6,2n < p \le 2 \times 10^9,0 \le b_0,A,B<p)$, where $p$ is a prime number. The meanings of $n$ and $p$ are described above. The rest of them is a generator of $a$, where $a_0=0$, $a_i=a_{i-1}+b_i+1$ and $b_i=(A\cdot b_{i-1}+B) \bmod p$ for all $1 \le i \le 2n$.
It is guaranteed that the sum of $n$ in all test cases does not exceed $10^7$.