1 #include <stdio.h>
2 #include <iostream>
3 #include <cstdlib>
4 #include <cmath>
5 #include <string>
6 #include <cstring>
7 #include <algorithm>
8 #include <stack>
9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <vector>
13 using namespace std;
14 typedef long long ll;
15 typedef unsigned long long ull;
16
17 #define Faster ios::sync_with_stdio(false),cin.tie(0)
18 #define Read freopen("in.txt", "r", stdin),freopen("out.txt", "w", stdout)
19 const int INF = 0x3f3f3f3f;
20 const int maxn = 1e7 + 5;
21
22 ll n, m, k, p, q, MOD, r;
23 ll a[maxn];
24 ll b[maxn];
25
26 int main()
27 {
28 Faster;
29 int T;
30 cin >> T;
31 while(T--){
32 cin >> n >> m >> k >> p >> q >> r >> MOD;
33 for(int i = 1;i <= n;i++){
34 if(i <= k){
35 cin >> a[i];
36 }
37 else{
38 a[i] = (p*a[i-1] + q*i + r)%MOD;
39 }
40 }
41 ll cnt, ans;
42 cnt = ans = 0;
43 for(int h = 1, t = 0, i = n;i >= 1;i--){
44 while(h <= t && a[b[t]] <= a[i]) t--;
45 b[++t] = i;
46 if(i+m-1 <= n){
47 while(b[h] >= i+m) h++;
48 ans += i^a[b[h]];
49 cnt += i^(t-h+1);
50 }
51 }
52 cout << ans << " " << cnt << endl;
53 }
54 return 0;
55 }