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

ll inf = 100000000000000000;

void solve() {
    int n, m; cin >> n >> m;
    vector<ll> a(m);
    ll mn = inf, mx = -inf;
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
    if (mn == mx) {
        cout << (ll)n * mn - mn * ((m-n)%2);
    }

    /*
    int n, m; cin >> n >> m;
    vector<int> b(m);
    vector<int> bo, bp;
    int c0 = 0;
    for (int i = 0; i < m; ++i) {
        int x; cin >> x;
        b[i] = x;
        if (x == 0) c0 ++;
        else if (x > 0) bp.push_back(x);
        else bo.push_back(x);
    }
    sort(bo.begin(), bo.end());
    sort(bp.rbegin(), bp.rend());
    sort(b.begin(), b.end());

    int n1 = bo.size();
    int n2 = bp.size();

    ll ans = 0;
    // ((n1 && c0 + n2) || (n2 && c0 + n1) || (c0 >= 2)) &&
    if (n > 1) {
        int i = 0;
        while (i < n1 && i < n2) {
            ans += -bo[i] + bp[i];
            ++i;
        }

        if (i == n1) {
            for (int j = 0; j < n-1; ++j) {
                ans += bp[i];
                i ++;
                if (i == n2) break;
            }
            int l = i, r = n2-1;
            while (l < r) {
                ans += bp[l] - bp[r];
                l++;
                r--;
            }
            if (l == r) ans -= bp[l];
        } else {
            for (int j = 0; j < m-1; ++j) {
                ans -= bo[i];
                i ++;
                if (i == n1) break;
            }
            int l = i, r = n1-1;
            while (l < r) {
                ans += -bo[l] + bo[r];
                l++;
                r--;
            }
            if (l == r) ans += bo[l];
        }
    } else if (n == 1) {
        int l = 0, r = m-1;

        while (l < r) {
            ans += b[l] - b[r];
            l++;
            r--;
        }
        ans = abs(ans);
        if (l == r) ans += abs(b[l]);
    }

    cout << ans << '\n';
    */
}

int main()
{

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

    int ttt = 1;
    cin >> ttt;
    while (ttt--) {
        solve();
    }
}
