/*All praise be to Allah*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef unsigned int long long uill;
typedef int long long ill;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll oo = 1LL<<30;

/* ///// ** function ** ///// */

void out(ll a[],ll n)
{
    for(int i=0; i<=n+5; i++)
        cout<<a[i]<<"  ";
    cout<<"\n";

}

void out(vector<ll> v)
{
    for(auto a:v )
        cout<<a<<"  ";
    cout<<"\n";

}

/* ///// ** code ** ///// */

ll a[300200],dp[300200],c[300200];





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

ll t;
cin>>t;
while(t--)
{
    memset(a,0,sizeof(a));
        memset(c,0,sizeof(c));
    memset(dp,-1,sizeof(dp));
    ll n,m,x,ans=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
        for(int i=0;i<m;i++)
    cin>>c[i];

    vector<pair<ll,ll> >v;

    for(int i=0;i<n;i++)
    {
        v.push_back({c[a[i]-1],a[i]-1});
    }

    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int j=0;
    for(auto u:v)
    {
        ll y=u.F,z=u.S;
        if(y<=c[j]){ans+=y;}
        else if(z>=j){ans+=c[j];j++;}
        else {ans+=y;}
    }

    cout<<ans<<"\n";

}



    return 0;
}
