#include <bits/stdc++.h>
using namespace std;
const int N = 50000;
bool check_prime(int n) {
  for (int i = 2; i < min(N, n); i++)
    if (n % i == 0) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    vector<long long> numbers(a);
    vector<long long> friends(b);
    for (long long& z : numbers) cin >> z;
    for (long long& z : friends) cin >> z;
    sort(numbers.rbegin(), numbers.rend());
    sort(friends.begin(), friends.end());
    long long cur = 0;
    long long ones = 0;
    long long ans = 0;
    while (friends[ones] == 1) {
      ans += numbers[cur] * 2;
      cur++;
      ones++;
      if (ones == b) break;
    }
    long long nonOnes = b - ones;
    for (int i = 0; i < nonOnes; i++) {
      ans += numbers[cur];
      cur++;
    }
    cur--;
    for (int i = ones; i < b; i++) {
      cur += friends[i] - 1;
      ans += numbers[cur];
    }
    cout << ans << '\n';
  }
}
