#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long tests;
  cin >> tests;
  while (tests--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> v(n), w(k);
    for (long long i = 0; i < n; i++) cin >> v[i];
    for (long long i = 0; i < k; i++) cin >> w[i];
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    reverse(v.begin(), v.end());
    reverse(w.begin(), w.end());
    long long ans = 0;
    for (long long i = 0; i < k; i++) {
      ans += v[i];
    }
    long long kk = 0, tmp = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (kk == k) break;
      long long d = w[kk];
      d -= 1;
      kk++;
      if (d == 0) {
        ans += v[tmp];
        tmp++;
        continue;
      }
      ans += v[i];
      i = i - d + 1;
    }
    cout << ans << '\n';
  }
}
