#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long n, m;
		cin>>n>>m;
		long k[n], c[m];
		for(long i=0;i<n;i++)
			cin>>k[i];
		sort(k,k+n,[](long& a,long& b){ return a>b; });
		for(long i=0;i<m;i++)
			cin>>c[i];
		long long p = 0;
		long long r = 0;
		for(long long i=0;i<n;i++)
		{
			assert(k[i]-1>=0 && k[i]-1 < m);
			if(p >= m)
				r += c[k[i]-1];
			else if(c[p] < c[k[i]-1])
				r += c[p++];
			else
				r += c[k[i]-1];
		}
		cout<<r<<"\n";
	}
}