#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, n, x, y, z, p, q, s, b, e, k;
  cin >> t;
  long long sum;
  while (t--) {
    sum = 0;
    cin >> n >> k;
    vector<int> v(n), v2(k);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    y = 0;
    z = n - 1;
    for (int i = 0; i < k; i++) {
      cin >> v2[i];
      if (v2[i] == 1) sum += (long long)v[z] + (long long)v[z--], y++;
    }
    int j = 0;
    sort(v2.begin(), v2.end(), greater<int>());
    for (int i = 0; i < k - y; i++) {
      x = v2[i] - 1;
      sum += (long long)v[j];
      while (x--) j++;
    }
    for (; j <= z; j++) sum += (long long)v[j];
    cout << sum << '\n';
  }
  return 0;
}
