#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll i,j,n,q;
    ll t;
    cin>>t;
    while (t--){
        ll m;
        cin>>n>>m;
        multiset<ll>mno;
        for (i=0;i<n;i++){
            mno.insert(0);
        }
        vector<ll>x(m);
        ll S=0;
        for (i=0;i<m;i++){
            cin>>x[i];
            auto z=*mno.begin();
            mno.erase(mno.begin());
            S-=2*z;
            S+=x[i];
            mno.insert(x[i]-z);
        }
        cout<<S<<'\n';
    }
    return 0;
}
