#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (long long &x : v) cin >> x;
  vector<long long> w(k);
  for (long long &x : w) cin >> x;
  sort(v.begin(), v.end());
  sort(w.rbegin(), w.rend());
  long long ans = 0;
  for (long long x : w) {
    if (x == 1) {
      ans += v[v.size() - 1] * 2;
      v.pop_back();
    }
  }
  long long at = 0;
  for (long long x : w) {
    if (x != 1) {
      ans += v[at] + v[v.size() - 1];
      v.pop_back();
      at += x - 1;
    }
  }
  cout << ans << '\n';
}
void solve(bool testcase) {
  long long t;
  cin >> t;
  while (t--) solve();
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve(true);
  return 0;
}
