#include<bits/stdc++.h>

#define ld long double
#define ll long long
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c)) {
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 300000 + 10;
const int mod = 1e9 + 7;
int t, n, m, k[N], c[N];
int a[N];
bool cmp(int x, int y)
{
	return k[x] > k[y];
}
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		read(n), read(m);
		for (int i = 1; i <= n; i++)read(k[i]),a[i]=i;
		for (int i = 1; i <= m; i++)read(c[i]);
		sort(a + 1, a + 1 + n,cmp);
		ll ans = 0, now = 1;
		for (int i = 1; i <= n; i++)
		{
			if (now <= m && now < k[a[i]])ans += c[now], now++;
			else ans += c[k[a[i]]];
		}
		printf("%lld\n", ans);
	}

	return 0;
}
