#include <bits/stdc++.h>
using namespace std;
const long double PI = 2.0 * acos(0);
const long long M = 1000000007;
long long binpow(long long a, long long b) {
  if (!b) return 1ll;
  long long temp = binpow(a, b >> 1ll);
  temp = (1ll * temp * temp) % M;
  if (b & 1) temp = (1ll * a * temp) % M;
  return temp;
}
void pre() {}
void solve() {
  long long n, m, k, i, j, l, r;
  bool flag;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  vector<long long> w(k);
  long long cnt = 0;
  for (long long i = 0; i < k; ++i) {
    cin >> w[i];
    if (w[i] == 1) cnt++;
  }
  sort(a.begin(), a.end());
  sort(w.begin(), w.end());
  long long ans = 0;
  j = n - 1;
  l = cnt;
  while (cnt) {
    ans += (2 * a[j]);
    j--;
    cnt--;
  }
  if (k == n) {
    cout << ans << '\n';
    return;
  }
  cnt = k - 1;
  i = 0;
  m = cnt;
  while (j >= 0 && cnt >= l) {
    ans += (a[j]);
    ans += (a[i]);
    w[cnt] -= 2;
    i++;
    while (w[cnt]) {
      i++;
      w[cnt]--;
    }
    cnt--;
    j--;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t, _;
  cin >> t;
  _ = t;
  while (t--) solve();
  return 0;
}
