#include <bits/stdc++.h>
using namespace std;
int a[200010], w[200010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (--t > -1) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= k; ++i) {
      cin >> w[i];
    }
    sort(a + 1, a + n + 1, greater<int>());
    sort(w + 1, w + 1 + k);
    long long answer = 0;
    int s = k;
    for (int i = 1; i <= k; ++i) {
      if (w[i] == 1) {
        answer += a[i] * 2;
      } else {
        answer += a[i];
        answer += a[s + w[i] - 1];
        s = s + w[i] - 1;
      }
    }
    cout << answer << '\n';
  }
}
