#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  long long ans = 0;
  for (int i = 0; i < T; i++) {
    long long ans = 0;
    int N, K;
    cin >> N >> K;
    vector<long long> v;
    for (int j = 0; j < N; ++j) {
      long long cur;
      cin >> cur;
      v.push_back(cur);
    }
    sort(v.begin(), v.end());
    int counter2 = 0;
    vector<long long> v2;
    for (int j = 0; j < K; ++j) {
      long long cur;
      cin >> cur;
      if (cur == 1) {
        ++counter2;
      } else {
        v2.push_back(cur - 1);
      }
    }
    sort(v2.begin(), v2.end());
    for (int j = 0; j < counter2; ++j) {
      ans += v[v.size() - j - 1];
    }
    for (int j = 0; j < K; ++j) {
      ans += v[v.size() - j - 1];
    }
    int curN = N - K;
    for (int i = 0; i < v2.size(); ++i) {
      for (int j = 0; j < v2[i]; ++j) {
        curN--;
      }
      ans += v[curN];
    }
    cout << ans << endl;
  }
  return 0;
}
