#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

#define int long long

int n;

int m;

signed main() {
    int tst;
    cin >> tst;
    while (tst--) {
        cin >> n >> m;
        vector<int> x(m);
        for (int i = 0; i < m; ++i) {
            cin >> x[i];
        }
        vector<int> x1 = x;
        sort(x.begin(), x.end());
        if (x[0] == x.back()) {
            if (n >= m) {
                cout << m * x[0] << '\n';
            } else {
                if (m % 2 == n % 2) {
                    cout << n * x[0] << '\n';
                } else {
                    cout << (n - 1) * x[0] << '\n';
                }
            }
            continue;
        }
        int bal = 0;
        int s = 0;
        for (int i = 0; i < m; ++i) {
            if (bal == 0) {
                s += x1[i];
                bal++;
            } else if (bal == n) {
                s -= x1[i];
                bal--;
            } else if (x1[i] == x.back()) {
                s += x1[i];
                bal++;
            } else {
                if (m - i + bal <= n) {
                    s += x1[i];
                    bal++;
                } else {
                    s -= x1[i];
                    bal--;
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}
