#include<bits/stdc++.h>
#define int long long

using namespace std;

void pujith22()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}



int32_t main()
{
	pujith22();
	int t;
	cin>>t;
	priority_queue<int,vector<int>,greater<int>> q2;
	priority_queue<int> q1;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int inp;
		int sol = 0;
		vector<int> arr1(n);
		vector<int> arr2(m);
		for(int i=0;i<n;i++)
		{
			cin>>arr1[i];

		}
		for(int j=0;j<m;j++)
		{
			cin>>arr2[j];
		}
		int ptr=0;
		sort(arr1.begin(),arr1.end(),greater<int>());
		for(int i=0;i<n;i++)
		{
			if(ptr==m)
			{
				for(int j=i;j<n;j++)
					sol += arr2[arr1[j]-1];
				break;
			}
			if(arr2[arr1[i]-1]<arr2[ptr])
			{
				sol += arr2[arr1[i]-1];
			}
			else
			{
				sol += arr2[ptr];
				ptr++;
			}
		}
		cout<<sol<<"\n";
	}
	return 0;

}