#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, k, cnt = 0, j, ans = 0, l, r;
    cin >> n >> k;
    long long ar[n + 1], w[k + 1];
    for (i = 1; i <= n; i++) {
      cin >> ar[i];
    }
    for (i = 1; i <= k; i++) {
      cin >> w[i];
      if (w[i] == 1) cnt++;
    }
    sort(ar + 1, ar + n + 1);
    j = n;
    for (i = 1; i <= cnt; i++) {
      ans += (2 * ar[j]);
      j--;
    }
    l = 1;
    r = j;
    sort(w + 1, w + k + 1);
    for (i = k; i >= 1; i--) {
      if (w[i] == 1) break;
      ans += ar[l] + ar[r];
      r -= 1;
      l += w[i] - 1;
    }
    cout << ans << "\n";
  }
}
