#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

mt19937 rnd(time(0));



int main() {
//    std::ios_base::sync_with_stdio(0);
//    std::cin.tie(0); std::cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        ll ans = 0;
        for (int i = (n + 1) / 2; i < n; i++) {
            ans += a[i];
        }
        int p = (n - 1) / 2, e = (n + 1) % 2;
        for (int i = 0; i < (n + 1) / 2; i++) {
            if (a[i] == 1) {
                continue;
            }
            while (a[i] > 1 && p >= i && k > 0) {
                a[i]--;
                k--;
                if (e % 2 == 0) {
                    ans += a[p--];
                }
                e ^= 1;
            }
            if (p < i || k == 0) {
                break;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
