#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mp make_pair
#define X first
#define Y second
const int maxn = 1e7+10;
int a[maxn];
int n, m, k, p, q, r, mod;
int A[maxn], B[maxn];
int main(){
ios::sync_with_stdio(false);
int t;
scanf("%d", &t);
while(t--){
scanf("%d%d%d%d%d%d%d", &n, &m, &k, &p, &q, &r, &mod);
for(int i=1; i<=k; i++){
scanf("%d", &a[i]);
}
for(int i=k+1; i<=n; i++){
a[i] = (1ll*p*a[i-1]+1ll*q*i+r)%mod;
}
deque<pii> dq;
while(!dq.empty()){
dq.pop_back();
}
dq.push_back(mp(a[n], n));
for(int i=n-1; i>=n-m+1; i--){
while(!dq.empty()&&(*--dq.end()).X<a[i]){
dq.pop_back();
}
dq.push_back(mp(a[i], i));
}
B[n-m+1] = dq.size();
A[n-m+1] = (*dq.begin()).X;
for(int i=n-m; i>=1; i--){
if(((*dq.begin()).Y)>m+i-1){
dq.pop_front();
}
while(!dq.empty()&&(*--dq.end()).X<=a[i]){
dq.pop_back();
}
dq.push_back(mp(a[i], i));
B[i] = dq.size();
A[i] = (*dq.begin()).X;
}
ll ans1=0, ans2 = 0;
for(int i=1; i<=n-m+1; i++){
ans1 += (ll(A[i])^(i));
ans2 += (ll(B[i])^(i));
}
printf("%lld %lld\n", ans1, ans2);
}
return 0;
}