#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define str string
#define pb push_back
#define ins insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define sz(a) (int)a.size()
#define int ll

mt19937 rnd(1488);

void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> c(m);
    for (int i = 0; i < m; i++){
        cin >> c[i];
    }
    if (*min_element(all(c)) == *max_element(all(c))){
        if (m <= n){
            cout << m * c[0] << "\n";
        }
        else{
            cout << c[0] * (n - 1 + (m - n + 1) % 2) << "\n";
        }
    }
}

int32_t main(){
    cin.tie(0)->ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif // LOCAL
    int _ = 1;
    cin >> _;
    while (_--){
        solve();
    }
}
