#include <bits/stdc++.h>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int abab = 0; abab < t; abab++) {
        int n, m;
        cin >> n >> m;
        vector<long long> a(m);
        for (int i = 0; i < m; i++) {
            cin >> a[i];
        }
        reverse(a.begin(), a.end());
        multiset<long long> pos;
        int cp = n, cm = 0;
        long long ans = 0;
        for (auto x : a) {
            if (cp > 0) {
                cp--;
                pos.insert(x);
                ans += x;
            } else {
                cp++;
                if (*pos.begin() < x) {
                    ans -= 2 * *pos.begin();
                    ans += x;
                    pos.erase(pos.begin());
                    pos.insert(x);
                } else {
                    ans -= x;
                }
            }
        }
        cout << ans << '\n';
    }
}
