#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define pii acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(n,x) scanf("%d%d",&n,&x)
#define pr(n) printf("%d",n)
#define scl(n) scanf("%I64d",&n)
#define scl2(n,m) scanf("%I64d%I64d",&n,&m)
#define prl(n) printf("%I64d",n)
#define loop(x,n) for(int i=x;i<n;i++)
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define mod 998244353
#define lv -100000000
typedef pair<int,int> pi;
#define fastio           ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
int a[300005],c[300005];
int main()
{
    int t,n,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<k;i++)
        {
            cin>>c[i];
        }
        sort(a,a+n);
        ll ans=0;
        int l=0,flag=0;
        for(int i=n-1;i>=0;i--)
        {
            if(flag==0 && c[l]<=c[a[i]-1]&&l<k)
            {
                ans+=c[l];
                l++;
                //cout<<"YES"<<endl;
            }
            else
            {
                flag++;
                ans+=c[a[i]-1];
            }
        }
        cout<<ans<<endl;
    }
}
