#include <bits/stdc++.h>

#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ld = long double;

const ll infll = (ll) 1e18;
const int inf = (int) 1e9;
const ll MOD = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod(ll a) {
    ll r = a % MOD;
    if (r < 0) {
        return r + MOD;
    }
    return r;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (auto &x : a) cin >> x;
    if (n < m) cout << a[0] * n - ((m - n) % 2 ? a[0] : 0) << '\n';
    else {
        cout << a[0] * m << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}