#include <bits/stdc++.h>
using namespace std;
#define int      long long
#define INT_MAX 2147483647
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
typedef vector<int> vi;
typedef pair<int,int> pii;
void solve(){
int n,m;
cin>>n>>m;
vi v1(n);
vector<pair<int,bool>> v2;
for(auto &a:v1)
    cin>>a;
rep(i,0,m){
    int a;
    cin>>a;
    v2.pb(mp(a,1));
}
    sort(v1.begin(),v1.end());
    reverse(v1.begin(),v1.end());
    int x=0;
    int ans=0;
    rep(i,0,n){
        if(v2[v1[i]-1].f>v2[x].f&&v2[x].s==1){
            ans+=v2[x].f;
            v2[x].s=0;
            x++;
        }
      else  {
            ans+=v2[v1[i]-1].f;
        }
    }
    cout<<ans<<endl;


}
signed  main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//   freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t=1;
cin>>t;
while(t--){
     solve();
 }
return 0;
}