#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef map<ll,ll> mll;
typedef vector<int> vi;
typedef set<ll> sll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
ll gcd(ll a, ll b) {return a == 0? b: gcd(b%a,a);}
ll lcm(ll a, ll b) {return a * (b / gcd(a,b));}
#define inf 1e17
#define pb(x) push_back(x)
#define rep(i, x,n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define fo(x) find_by_order(x)
#define ok(x) order_of_key(x)
const ll mod = 998244353;
const int M = 1e4;
const int K = 20;
int lg[3 * M + 1];
struct sparseTable {
vector<vi> st;
void build(vi &nums){
int n = nums.size();
st.resize(K + 1, vi(n));
st[0] = nums;
for (int i = 1; i <= K; i++)
for (int j = 0; j + (1 << i) <= n; j++)
st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
int query(int L, int R){
int i = lg[R - L + 1];
return max(st[i][L], st[i][R - (1 << i) + 1]);
}
};
ii dp[3 * M + 1][M + 1];
pll f(int X, int Y, vi &cost, sparseTable &st, int mx) {
if (X >= mx && Y == 0) return {0, 1};
if (dp[X][Y].first != -1) return dp[X][Y];
ii res = {INT_MAX, 0};
rep(i, 1, cost.size()) {
int broken = st.query(X + 1, X + i);
ii tran = f(X + i, max({0, Y - i, broken}), cost, st, mx);
tran.first += cost[i];
if (tran.first < res.first) {
res = tran;
}else if (res.first == tran.first) {
res.second = (res.second + tran.second) % mod;
}
}
return dp[X][Y] = res;
}
void solve() {
int n, m; cin >> n >> m;
rep(i, 0, 3 * m + 1)
rep(j, 0, m + 1)
dp[i][j] = {-1, -1};
vi health(3 * m + 1);
vi A(n), B(n);
rep(i, 0, n) cin >> A[i];
rep(i, 0, n) cin >> B[i];
rep(i, 0, n) {
health[B[i]] = max(health[B[i]], A[i]);
}
sparseTable st; st.build(health);
int k; cin >> k;
vi cost(k + 1);
rep(i, 1, k + 1) cin >> cost[i];
ii res = f(0, 0, cost, st, *max_element(all(B)));
cout << res.first << " " << res.second << "\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
lg[1] = 0;
for (int i = 2; i <= 3 * M; i++)
lg[i] = lg[i/2] + 1;
int t = 1; cin >> t;
while (t--) solve();
return 0;
}