#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using ull = unsigned long long;

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

mt19937 rnd(1337);

constexpr int inf = 1e18;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int &i : x)
        cin >> i;
    reverse(all(x));
    map<int, int> cnt;
    int ans = 0, mpt = n;
    for (int i : x) {
        if (mpt > 0) {
            --mpt;
            ans += i;
            ++cnt[i];
        } else {
            if (i <= cnt.begin()->first) {
                ans -= i;
                ++mpt;
            } else {
                ans -= cnt.begin()->first;
                if (cnt.begin()->second == 0)
                    cnt.erase(cnt.begin());
                ans += i;
                ++cnt[i];
                ++mpt;
            }
        }
    }
    cout << ans << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) solve();
//    cerr << fixed << setprecision(10) << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
}
