#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 1e9 + 10;
const long long INF = 1e18;
const long double EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n), w(k);
    for (int i = 0; i < (n); ++i) cin >> a[i];
    for (int i = 0; i < (k); ++i) {
      cin >> w[i];
      w[i]--;
    }
    sort(a.begin(), a.end(), greater<long long>());
    sort(w.begin(), w.end());
    long long ans = 0, idx = k - 1;
    for (int i = 0; i < (k); ++i) {
      ans += a[i];
      if (w[i]) {
        idx += w[i];
        ans += a[idx];
      } else
        ans += a[i];
    }
    cout << ans << '\n';
  }
  return 0;
}
