#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, ans = 0;
  vector<long long> v;
  vector<long long> w;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    long long val;
    cin >> val;
    v.push_back(val);
  }
  sort(v.begin(), v.end());
  long long one = 0;
  for (int i = 1; i <= k; i++) {
    long long x;
    cin >> x;
    if (x == 1)
      one++;
    else
      w.push_back(x);
  }
  while (one--) {
    ans += 2 * v[v.size() - 1];
    v.pop_back();
  }
  sort(v.begin(), v.end());
  sort(w.rbegin(), w.rend());
  long long l = 0, pos = 0;
  while (pos < w.size()) {
    ans += v[l];
    l += w[pos] - 1;
    pos++;
  }
  for (int i = l; i < v.size(); i++) ans += v[i];
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
