#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sc second
#define pb push_back

const int INF = 1e9 + 1;
const int mod = 1e9+9;
const int base = 1e9;

int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n, m;
        cin>>n>>m;
        vector<int> k(n), c(m);
        for(int i = 0; i < n; i++) {
            cin>>k[i];
        }
        sort(k.rbegin(), k.rend());
        for(int i = 0; i < m; i++) {
            cin>>c[i];
        }
        int64_t ans = 0;
        int i = 0;
        for(auto p : k) {
            if(i < p) {
                ans += c[i];
                i++;
            } else {
                ans += c[p-1];
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}
