#include <bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

#define all(a) a.begin(), a.end()

using ordered_set = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef _GLIBCXX_DEBUG
    freopen("input", "r", stdin);
#endif
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int &i: x)
        cin >> i;
    reverse(all(x));
    int mx = *max_element(all(x));
    ll ans = 0, b = 0;
    for (int i = 0; i < m; i++) {
        if (x[i] == mx) {
            if (b + 1 <= n) {
                b++;
                ans += x[i];
            } else {
                b--;
                ans -= x[i];
            }
        } else {
            if (b > 0) {
                b--;
                ans -= x[i];
            } else {
                b++;
                ans += x[i];
            }
        }
    }
    cout << ans << '\n';
}