#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    int N, K;
    cin >> N >> K;
    vector<int> A(N), W(K);
    for (auto& x : A) cin >> x;
    for (auto& x : W) {
      cin >> x;
      x--;
    }
    sort(A.begin(), A.end());
    sort(W.begin(), W.end());
    vector<vector<int>> friends(K);
    int idx = N - 1;
    for (int k = 0; k < K; ++k) {
      friends[k].push_back(A[idx--]);
    }
    for (int k = 0; k < K; ++k) {
      if (W[k]) {
        idx -= W[k];
        friends[k].push_back(A[idx + 1]);
      }
    }
    long long ans = 0;
    for (auto x : friends) {
      ans += *max_element(x.begin(), x.end());
      ans += *min_element(x.begin(), x.end());
    }
    cout << ans << '\n';
  }
  return 0;
}
