#ifndef SEREGA
#include <bits/allocator.h>
#pragma GCC target("avx2,popcnt")
#pragma GCC optimize("O3,no-stack-protector")
#endif
#include <bits/stdc++.h>
using namespace std;
#define int int64_t


int n, m;
vector<int> x;
vector<int> a;
int answer = 0;
map<pair<vector<int>, int>, int> cache;
int dfs(vector<int> &ssf, int index) {
    if (cache.contains({ssf, index})) return cache[{ssf, index}];
    if (index == m) {
        return accumulate(ssf.begin(), ssf.end(), int(0));
    }
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        ssf[i] = x[index] - ssf[i];
        mx = max(mx, dfs(ssf, index + 1));
        ssf[i] = x[index] - ssf[i];
    }
    return cache[{ssf, index}] = mx;
}
void solve() {
    cin >> n >> m;
    x.assign(m, {});
    a.assign(n, {});
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    if (m <= n) {
        cout << x[0] * m << '\n';
        return;
    }
    cout << ((m - n) & 1 ? x[0] * (n - 1) : x[0] * (n)) << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) solve();
}