#include <bits/stdc++.h>
using namespace std;
template <class X>
bool mini(X& a, const X& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class X>
bool maxi(X& a, const X& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef const int& ci;
const int N = 2e5 + 1;
int n, k;
void enter() {}
void solve() {
  int t;
  for (cin >> t; t--;) {
    cin >> n >> k;
    long long res = 0;
    vector<int> a(n), w;
    for (int& x : a) cin >> x;
    sort(a.begin(), a.end());
    for (int i = 1, _b = (k) + 1; i < _b; ++i) {
      int x;
      cin >> x;
      if (x == 1) {
        res += a.back() << 1;
        a.pop_back();
      } else
        w.emplace_back(x);
    }
    sort(w.begin(), w.end());
    for (int x : w) {
      res += a.back();
      a.pop_back();
    }
    for (int& x : w) {
      for (int i = 1, _b = (x - 2) + 1; i < _b; ++i) a.pop_back();
      res += a.back();
      a.pop_back();
    }
    cout << res << '\n';
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  enter();
  solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms";
}
