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

using namespace __gnu_pbds;
using namespace std;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//less_equal

//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,bmi2,fma,popcnt")

#define int long long
#define x first
#define y second

int inf = 1'000'000'000'000'000'000;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    for (auto &i : v) {
        cin >> i;
    }
    if (m <= n) {
        cout << m * v[0] << '\n';
    }else {
        cout << (n - 1) * v[0] + ((m - (n - 1)) % 2) * v[0] << '\n';
    }
}

signed main() {
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
#endif
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
}