#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
long long a[maxn];
int w[maxn];
vector<long long> E[maxn];
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      E[i].clear();
    }
    for (int i = 1; i <= k; i++) cin >> w[i];
    sort(a + 1, a + 1 + n, greater<long long>());
    sort(w + 1, w + 1 + k, greater<int>());
    long long ans = 0;
    int b = 1;
    for (int i = k; i >= 1; i--) {
      E[i].push_back(a[b++]);
    }
    int r = n;
    int g = 1;
    while (g <= k) {
      while ((int)E[g].size() < w[g]) {
        E[g].push_back(a[r--]);
      }
      g++;
    }
    for (int i = 1; i <= k; i++) {
      long long max1 = -1e9 - 1, min1 = 1e9 + 7;
      for (auto &v : E[i]) {
        max1 = max(max1, v);
        min1 = min(min1, v);
      }
      ans += max1 + min1;
    }
    cout << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
