#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long int a[n];
    long long int w[k];
    long long int ans1 = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      ans1 += a[i];
    }
    for (long long int i = 0; i < k; i++) {
      cin >> w[i];
    }
    sort(a, a + n);
    sort(w, w + k);
    if (n == k) {
      cout << 2 * ans1 << endl;
    } else {
      long long int j = n - 1;
      long long int ans = 0;
      long long int p = 0;
      long long int y = 0;
      long long int x = n - 1;
      long long int cn = 0;
      while (y < k) {
        if (w[y] != 1) break;
        ans = ans + 2 * a[x];
        x--;
        y++;
      }
      j = j - y;
      for (long long int i = k - 1; i >= y; i--) {
        ans = ans + (a[j] + a[p]);
        j--;
        p = p + w[i] - 1;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
