#include<bits/stdc++.h>
using namespace std;
using ll = long long int;


void solve() {
	ll n, m; cin >> n >> m;
	vector<ll>k(n);
	vector<ll>c(m);
	for (ll i = 0; i < n;i++) {
		cin >> k[i];
	}
	for (ll i = 0; i < m;i++) {
		cin >> c[i];
	}
	sort(k.rbegin(),k.rend());
	vector<ll>ans(n);
	for (ll i = 0; i < n;i++) {
		ans[i] = c[k[i] - 1];
	}
	ll h = 0;
	ll sum = 0;
	for (ll i = 0; i < n;i++) {
		if (c[h]<ans[i] && c[h]!=-1) {
			ans[i] = c[h];
			c[h] = -1;
			h++;
		}
		sum += ans[i];
	}
	cout << sum << endl;
}


int main() {
	ll n; cin >> n;
	for (ll i = 0; i < n;i++) {
		solve();
	}

	return 0;
}