#include <bits/stdc++.h>

#define ll long long

using namespace std;

void fast_in_out() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
ll n,i,x[300010],m,j;
const ll inf=1e18;
int main() {
    fast_in_out();
    ll t;
    cin >> t;
    while(t--){
        cin >> n >> m;
        for(i=m;i>=1;i--)cin >> x[i];
        if(m<=n){
            cout << m*x[1] << "\n";
        }else{
            cout << n*x[1]-(m-n)%2*x[1];
        }
    }
    return 0;
}
