#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> f;
    for (int i = 0; i < n; ++i) {
        f.insert(0);
    }
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        auto v = *f.begin();
        f.erase(f.begin());
        f.insert(x - v);
        ans += x - 2 * v;
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
