#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using ll = long long;

using namespace std;

using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

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