#include <algorithm>    // std::sort
#include <iostream>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		int *k = new int[n];
		long long *c = new long long[m];
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}
		std::sort(k, k + n);

		for (int i = 0; i < m; i++) {
			cin >> c[i];
		}
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += c[k[i] - 1];
		}
		int index = 0;
		bool submitted = false;
		while (index < n) {
			long long diff = c[k[n - index - 1] - 1] - c[index];
			if (diff > 0) {
				sum -= diff;
				index++;
			}
			else {
				cout << sum << "\n";
				submitted = true;
				break;
			}
		}
		if (!submitted) {
			cout << sum << "\n";
		}
	}
}