#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
const int N = 666666 + 100;
int mod = 998244353;
int lst[N], good[N], a[N];
int ways[N], f[N], cnt[N], pr[N];
vector <int> occ;
void add(int &a, int b) {
a += b;
while (a >= mod)
a -= mod;
while (a < 0)
a += mod;
}
void solve() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
occ.push_back(a[i]);
}
sort(occ.begin(), occ.end());
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(occ.begin(), occ.end(), a[i]) - occ.begin();
good[i] = max(good[i - 1], lst[a[i]]);
lst[a[i]] = i;
}
for (int i = 0; i < q; i++) {
int k;
cin >> k;
deque <int> dq;
f[0] = 0;
cnt[0] = 1;
for (int j = 1; j <= n; j++) {
if (j >= k) {
while ((int)dq.size() && f[dq.back()] < f[j - k]) {
int t = dq.back();
add(ways[f[t]], -cnt[t]);
dq.pop_back();
}
dq.push_back(j - k);
add(ways[f[j - k]], cnt[j - k]);
}
while ((int)dq.size() && dq.front() < good[j]) {
int t = dq.front();
add(ways[f[t]], -cnt[t]);
dq.pop_front();
}
if ((int)dq.size()) {
int t = dq.front();
f[j] = f[t] + 1;
pr[j] = max(pr[j - 1], f[j]);
if (pr[j - 1] == f[j]) {
cnt[j] = (ways[f[t]] + cnt[j - 1]) % mod;
}
if (pr[j - 1] < f[j]) {
cnt[j] = ways[f[t]];
}
if (pr[j - 1] > f[j]) {
cnt[j] = cnt[j - 1];
}
} else {
f[j] = 0;
cnt[j] = 1;
}
}
int ans = cnt[n], mx = pr[n];
for (int j = 0; j <= n; j++) {
f[j] = cnt[j] = ways[j] = pr[j] = 0;
}
//if (mx == 0)
//ans = 1;
cout << mx << " " << ans << '\n';
}
for (int i = 0; i <= n + 1; i++) {
good[i] = lst[i] = 0;
}
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
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ICAgICAgICBjaW4gPj4gazsKCiAgICAgICAgZGVxdWUgPGludD4gZHE7CiAgICAgICAgZlswXSA9IDA7CiAgICAgICAgY250WzBdID0gMTsKCiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gbjsgaisrKSB7CiAgICAgICAgICAgIGlmIChqID49IGspIHsKICAgICAgICAgICAgICAgIHdoaWxlICgoaW50KWRxLnNpemUoKSAmJiBmW2RxLmJhY2soKV0gPCBmW2ogLSBrXSkgewogICAgICAgICAgICAgICAgICAgIGludCB0ID0gZHEuYmFjaygpOwogICAgICAgICAgICAgICAgICAgIGFkZCh3YXlzW2ZbdF1dLCAtY250W3RdKTsKICAgICAgICAgICAgICAgICAgICBkcS5wb3BfYmFjaygpOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIGRxLnB1c2hfYmFjayhqIC0gayk7CiAgICAgICAgICAgICAgICBhZGQod2F5c1tmW2ogLSBrXV0sIGNudFtqIC0ga10pOwogICAgICAgICAgICB9CgogICAgICAgICAgICB3aGlsZSAoKGludClkcS5zaXplKCkgJiYgZHEuZnJvbnQoKSA8IGdvb2Rbal0pIHsKICAgICAgICAgICAgICAgIGludCB0ID0gZHEuZnJvbnQoKTsKICAgICAgICAgICAgICAgIGFkZCh3YXlzW2ZbdF1dLCAtY250W3RdKTsKICAgICAgICAgICAgICAgIGRxLnBvcF9mcm9udCgpOwogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoKGludClkcS5zaXplKCkpIHsKICAgICAgICAgICAgICAgIGludCB0ID0gZHEuZnJvbnQoKTsKICAgICAgICAgICAgICAgIGZbal0gPSBmW3RdICsgMTsKICAgICAgICAgICAgICAgIHByW2pdID0gbWF4KHByW2ogLSAxXSwgZltqXSk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGlmIChwcltqIC0gMV0gPT0gZltqXSkgewogICAgICAgICAgICAgICAgICAgIGNudFtqXSA9ICh3YXlzW2ZbdF1dICsgY250W2ogLSAxXSkgJSBtb2Q7CiAgICAgICAgICAgICAgICB9IAoKICAgICAgICAgICAgICAgIGlmIChwcltqIC0gMV0gPCBmW2pdKSB7CiAgICAgICAgICAgICAgICAgICAgY250W2pdID0gd2F5c1tmW3RdXTsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZiAocHJbaiAtIDFdID4gZltqXSkgewogICAgICAgICAgICAgICAgICAgIGNudFtqXSA9IGNudFtqIC0gMV07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBmW2pdID0gMDsKICAgICAgICAgICAgICAgIGNudFtqXSA9IDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGludCBhbnMgPSBjbnRbbl0sIG14ID0gcHJbbl07CgogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDw9IG47IGorKykgewogICAgICAgICAgICBmW2pdID0gY250W2pdID0gd2F5c1tqXSA9IHByW2pdID0gMDsKICAgICAgICB9CgogICAgICAgIC8vaWYgKG14ID09IDApCiAgICAgICAgICAgIC8vYW5zID0gMTsKICAgICAgICBjb3V0IDw8IG14IDw8ICIgIiA8PCBhbnMgPDwgJ1xuJzsKICAgIH0KCiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuICsgMTsgaSsrKSB7CiAgICAgICAgZ29vZFtpXSA9IGxzdFtpXSA9IDA7CiAgICB9Cn0KCnNpZ25lZCBtYWluKCkgewogICAgY2luLnRpZSgwKSAtPiBzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwoKICAgIHdoaWxlICh0LS0pIHsKICAgICAgICBzb2x2ZSgpOwogICAgfQoKICAgIHJldHVybiAwOwp9CgovKgoyCjUgMgoxIDIgMSAyIDEKMiAzCjYgMgoxIDIgMyA0IDUgNgozIDUKKi8=