The first line of the input contains an integer $T(1\leq T\leq2000)$, denoting the number of test cases.
In each test case, there are $7$ integers $n,m,k,p,q,r,MOD(1\leq m,k\leq n\leq 10^7,5\leq p,q,r,MOD\leq 10^9)$ in the first line, denoting the number of contestants, the length of interval, and the parameters $k,p,q,r,MOD$.
In the next line, there are $k$ integers $a_1,a_2,...,a_k(0\leq a_i\leq 10^9)$, denoting the rating of the first $k$ contestants.
To reduce the large input, we will use the following generator. The numbers $p,q,r$ and $MOD$ are given initially. The values $a_i(k<i\leq n)$ are then produced as follows :
\begin{eqnarray*}
a_i&=&(p\times a_{i-1}+q\times i+r)\bmod MOD
\end{eqnarray*}
It is guaranteed that $\sum n\leq 7\times 10^7$ and $\sum k\leq 2\times 10^6$.