#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 1)       return (a * pw(a * a, b / 2));     else       return (1 * pw(a * a, b / 2));   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n], b[k];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int n1 = 0;     for (int i = 0; i < k; i++) {       cin >> b[i];       if (b[i] == 1) n1++;     }     sort(b, b + k);     long long ans = 0;     for (int i = 0; i < n1; i++) ans += (a[n - 1 - i] * 2);     long long st = 0, en = n - 1 - n1;     for (long long i = k - 1; i >= n1; i--) {       if (b[i] == 1) {         ans += (a[en] * 2);         en--;       } else {         ans += a[en];         b[i]--;         en--;         ans += a[st];         st += b[i];       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }   