#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdio>
#include <utility> 
#include <queue>
#include <math.h>
#include <set>
#include <bitset>
#include <cmath>
#include <bitset>
#include <stack>
#include <cstring>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t; cin >> t;
    while(t--) {
        int n, m; cin >> n >> m;
        vector<ll> k(n + 1);
        vector<ll> c(m + 1);
        for(int i = 1; i <= n; i++) cin >> k[i];
        for(int i = 1; i <= m; i++) cin >> c[i];
        int idx = 1;
        sort(k.begin(), k.end());
        ll ans = 0;
        for(int i = n; i >= 1; i--) {
            if(idx > k[i] || c[k[i]] < c[idx]) ans += c[k[i]];
            else {
                ans += c[idx];
                idx++;
            }
        }
        cout << ans << '\n';
    }
}