#include <bits/stdc++.h>
#define pb push_back
#define int long long

using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pi = pair<int, int>;

pi mp(int x, int y) {
    return make_pair(x, y);
}

void solve() {
    int n, m;
    cin >> n >> m;

    set<pi> q;

    int curs = 0;

    for (int i = 0; i < n; ++i) {
        q.insert(mp(0, i));
    }

    // vi x(m);
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        auto [el, id] = *q.begin();
        q.erase(q.begin());
        curs += x - 2 * el;
        q.insert(mp(x - el, id));
    }

    cout << curs << endl;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }
}