#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, k, x, q, ans1, ans2, y, l, ans, m;
long long minn = INT_MAX, temp1, temp2, maxx = INT_MIN, num1, num2, num;
long long sum;
long long c[201];
long long a[200000], p1;
long long a1[200000];
string s1, s2;
int main() {
  cin >> q;
  while (q--) {
    cin >> n >> k;
    sum = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < k; i++) {
      cin >> a1[i];
      sum += a1[i];
    }
    sort(a, a + n);
    sort(a1, a1 + k);
    ans = 0;
    for (int i = n - 1; i >= n - k; i--) {
      ans += a[i];
    }
    int i = n - k - 1;
    int j = n - 1;
    num = 0;
    while (num < k) {
      if (a1[num] == 1) {
        ans += a[j];
        j--;
      } else {
        ans += a[i - a1[num] + 2];
        i = i - a1[num] + 1;
      }
      num++;
    }
    cout << ans << "\n";
  }
}
