//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#pragma GCC target("avx, avx2, tune=native")
#define int long long
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pi pair<int, int>


using namespace std;

struct fenwtree{
    int sz;
    vector<int> t;
    
    void init(int n) {
        t.assign(n + 1, 0);
        sz = n;
    }
    
    void add(int i, int v) {
        for (; i <= sz; i += i & (-i)) {
            t[i] += v;
        }
    }
    
    int sum(int r) {
        int res = 0;
        for (; r > 0; r -= r & (-r)) {
            res += t[r];
        }
        return res;
    }
    
    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    vector<int> crd = x;
    sort(all(crd));
    crd.resize(unique(all(crd)) - crd.begin());
    vector<int> bg(n);
    int k = crd.size();
    fenwtree fw;
    fw.init(k);
    for (int i = 0; i < m; ++i) {
        int c = lower_bound(all(crd), x[i]) - crd.begin();
        bg[i] = fw.sum(c + 1, k);
        fw.add(c + 1, 1);
    }
    n = min(n, m);
    int p = n + (m - n) / 2;
    int c = n, res = 0;
    for (int i = m - 1; i >= 0; --i) {
        if (c == n || p >= bg[i]) {
            res += x[i];
            --c;
            --p;
        } else {
            res -= x[i];
            ++c;
        }
    }
    cout << res << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
