//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
//#define _GLIBCXX_DEBUG 1
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define forsn(i,s,e) for(ll i = s; i <= e; i++)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln '\n'
#define all(x) x.begin(), x.end()

const ll inf = INT64_MAX;

ll n, m;
vector <ll> x;

ll solve() {
    ll res = x[0] * min(n, m);
    ll d = m - n;
    if (d < 0)
        return res;
    if (d % 2 == 1)
        res -= x[0];
    return res;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    ll t;
    cin >> t;
    while (t--) {
        x.clear();
        cin >> n >> m;
        x.resize(m);
        for (ll& i: x)
            cin >> i;
        ll res = solve();
        cout << res << ln;
    }

    return 0;
}
