#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<long long> arr(m);
    for(int i = 0; i < m; i++) cin >> arr[i];
    sort(arr.rbegin(), arr.rend());
    multiset<long long> cs;
    for(int i = 0; i < n; i++) cs.insert(i);
    for(auto x : arr) {
        long long aa = *cs.begin();
        cs.erase(cs.begin());
        aa = x - aa;
        cs.insert(aa);
    }
    long long ans = 0;
    for(auto i : cs) ans += i;
    cout << ans << '\n';
}

/*
a = x1 - a
a = x2 - a = x2 - (x1 - a) = x2 - x1 + a = x2 - x1
a = x3 - a = x3 - (x2 - x1) = x3 - x2 + x1
a = x4 - a = x4 - (x3 - x2 + x1) = x4 - x3 + x2 - x1
*/

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