#include<bits/stdc++.h>
#define lli long long int
using namespace std;
#define code_phat_jaayegaa ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int M=1e8;
void yash()
{
  //code_phat_jaayegaa;
  #ifndef ONLINE_JUDGE
freopen("streamlined_input.txt","r",stdin);
freopen("streamlined_output.txt","w",stdout);   
   #endif
}

void run_tc(int testcase)
{
      int n,m;
      scanf("%d %d",&n,&m);
      int x[n+1];
      
      for(int i=1;i<=n;i++)
      scanf("%d",&x[i]);
      lli y[m+1];
      
      for(int i=1;i<=m;i++)
      scanf("%lld",&y[i]);
      
      sort(x+1,x+n+1,greater<int>());
      
      lli val=0;
      for(int i=1;i<=n;i++)
      {
            if(i<x[i])
              val+=y[i];
            else
              val+=y[x[i]];

      }
      printf("%lld\n",val);
   return;
}

int main()
{
   yash();
  int t;
  scanf("%d",&t);
  for(lli testcase=1;testcase<=t;testcase++)
  {
     run_tc(testcase);
  }
  return 0;
}