#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define F first
#define S second
#define endl '\n'
#define int long long
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<
    T,
    null_type,
    less<T>,
    rb_tree_tag,
    tree_order_statistics_node_update
>;
template <typename T>
using ordered_set_desc = tree<
    T,
    null_type,
    greater<T>,
    rb_tree_tag,
    tree_order_statistics_node_update
>;
#define T int t;cin>>t;while(t--)

void Abady() {
    T{
        int n,k; cin >> n >> k;
        ordered_set<pair<int,int>> st;
        for (int i=1;i<=n;i++) {
            int x; cin >> x;
            st.insert({i,x});
        }
        int ans=0;
        while (st.size()>=k) {
            pair<int,int> l = *st.find_by_order(k-1), r = *st.find_by_order(st.size()-k);
            if (l.S >= r.S) {
                ans += l.S;
                st.erase(l);
            }
            else {
                ans += r.S;
                st.erase(r);
            }
        }
        cout << ans << endl;
    }
}

signed main() {
#ifdef ABADY
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast;
    Abady();
}