#include <bits/stdc++.h>
using namespace std;
const long long MN = 2e5 + 7;
vector<long long> v[MN];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (long long i = 0; i <= n; i++) v[i].clear();
    long long a[n], w[k];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long i = 0; i < k; i++) {
      cin >> w[i];
    }
    sort(w, w + k);
    sort(a, a + n);
    for (long long i = 0; i < k / 2; i++) swap(w[i], w[k - i - 1]);
    long long po = 0;
    for (long long i = 0; i < n - k; i++) {
      while (w[po] == v[po].size() + 1) po++;
      v[po].push_back(a[i]);
    }
    long long ans = 0;
    long long qf = 1;
    for (long long i = 0; i < k; i++) {
      ans += a[n - i - 1];
      if (v[i].size())
        ans += v[i][0];
      else
        ans += a[n - qf], qf++;
    }
    cout << ans << '\n';
  }
}
