#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x]) m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)5e6+100;
const int inf=(int)1e9+2;
#define filename ""
    int n,m;
    int a[N];
    int k[N];
bool check(int x)
{
    int i;
    fo(i,x)
    {
        if (i>k[n-x+i]) re 0;
    }
    re 1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        int i;
        cin>>n>>m;
        fo(i,n)
        {
            cin>>k[i];
            k[i]--;
        }
        sort(k,k+n);
        fo(i,m)
        {
            cin>>a[i];
        }
        int l=1;
        int r=n;
        int o=0,c;
        while(l<=r)
        {
            c=(l+r)>>1;
            if (check(c))
            {
                o=c;
                l=c+1;
            }
            else
            {
                r=c-1;
            }
        }
        ll sum=0;
        fo(i,n)
        {
            sum+=a[k[i]];
        }
        ll ans=sum;
        fo(i,o)
        {
            sum-=a[k[n-1-i]];
            sum+=a[i];
            ans=min(ans,sum);
        }
        cout<<ans<<'\n';
    }
}
