#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    long long int n, k, num;
    cin >> n >> k;
    priority_queue<long long int> q;
    long long int krr[k + 1], maxi[k + 1], mini[k + 1];
    for (long long int i = 1; i <= n; i++) {
      cin >> num;
      q.push(num);
    }
    for (long long int i = 1; i <= k; i++) {
      maxi[i] = q.top();
      q.pop();
      cin >> num;
      num--;
      krr[i] = num;
    }
    sort(krr + 1, krr + k + 1);
    for (long long int i = 1; i <= k; i++) {
      if (krr[i] == 0) {
        mini[i] = maxi[i];
        continue;
      }
      for (long long int j = 1; j <= krr[i]; j++) {
        mini[i] = q.top();
        q.pop();
      }
    }
    long long int sum = 0;
    for (long long int i = 1; i <= k; i++) {
      sum = sum + maxi[i] + mini[i];
    }
    cout << sum << "\n";
  }
  fclose(stdin);
  fclose(stdout);
}
