#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(k, n) for(int i=k; i<n; i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF (int)1e9
#define EPS 1e-9
#define mod 1000000007

typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef map<ll, ll> mll;
typedef unordered_set<int> usi;
typedef set<int> seti;
typedef vector<string> vstr;
//=======================

bool cmp(int a, int b) {
    return a>b;
}



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    
    //WRITE THE CODE HERE
	int t;
    cin>>t;
    while(t--){

        bool f = true;
        int n, m;
        cin>>n>>m;

        int k[n], c[m];

        fo(0, n) cin>>k[i];

        fo(0, m) cin>>c[i];

        sort(k, k+n, cmp);

        ll totalCost=0; int j=1;
        fo(0, n){

            if(f && k[i]>=j ) {
                totalCost+=c[j-1];
                j++;
            }
            else{
                totalCost+= c[k[i]-1];
                f = false;
            }

        }

        cout<<totalCost<<" "<<'\n';

    }
    

}

