#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define int long long

const int MAX = 3e5 + 7;

int dp[MAX][101];

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m + 1);
    int mx = 0;
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    reverse(a.begin() + 1, a.end());
    int res = 0;
    int lf = n; //c0
    int cntmx = 0;
    for (int i = 1; i <= m; i++) {
        cntmx += mx == a[i];
    }
    for (int i = 1; i <= m; i++) {
        if (a[i] == mx) {
            if (lf) {
                lf--;
                res += a[i];
            } else {
                lf++;
                res -= a[i];
            }
            cntmx--;
        } else {
            if (lf > cntmx) {
                lf--;
                res += a[i];
            } else {
                lf++;
                res -= a[i];
            }
        }
    }
    cout << res << '\n';
}

int32_t main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
}