//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using ll = long long;
using ld = long double;
const ll inf = 1e18;

#define all(a) a.begin(), a.end()
#define pb push_back

using namespace std;
using namespace literals;
//using namespace __gnu_pbds;

//using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//gp_hash_table<ll, ll> s;

mt19937 rnd;

void solve();
void precalc();

int main() {
#ifdef LOCAL:
    freopen("INPUT.TXT", "r", stdin);
    freopen("OUTPUT.TXT", "w", stdout);
    const auto start = chrono::steady_clock::now();
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    precalc();
    bool cfmode = true;
    if(cfmode) {
        ll t;
        cin >> t;
        while(t--) {
            solve();
        }
    } else {
        solve();
    }
#ifdef LOCAL:
    const auto end = chrono::steady_clock::now();
    cout << "\n";
    cout << fixed << setprecision(10) << "xxxTIMExxx: " << (end - start) / 1ms;
#endif
}

void precalc() {

}

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    ll x;
    for(int i = 0; i < m; i++) {
        cin >> a[i];
        x = a[i];
    }
    if(n >= m) {
        cout << x * m;
    } else {
        m -= n;
        cout << x * n - x * (m % 2);
    }
    cout << "\n";
}
