#include <bits/stdc++.h>

#define int long long
using namespace std;

const int INF = 2e16;

void solve();

signed main() {
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
        cout << "\n";
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> arr(m);
    for (int i = 0; i < m; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int ans = 0;
    for (int i = 0; i < n / 2; i++) {
        ans += arr[n - i - 1] - arr[i];
    }
    if (m % 2 == 1) {
        if (n == 1) {
            ans -= arr[n / 2];
        } else {
            ans += arr[n/ 2];
        }
    }
    cout << ans;
}