#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0);
    vector<int> b(m, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(b.begin(), b.end());
    int l = 0, r = n - 1, p = 0;
    long long int sum = 0;
    while (p < m && b[p] == 1) sum += 2 * a[r], r--, p++;
    for (int i = m - 1; i >= p; i--) {
      int count = b[i] - 1;
      sum += a[r] + a[l];
      r--, l++, b[i] -= 2;
      while (b[i]--) l++;
    }
    cout << sum << endl;
  }
  return 0;
}
