#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;
using ll = long long;
using ld = long double;

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename T>
//using oset = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int ll

void solve() {
    int n, m;
    cin >> n >> m;

    int x;
    for (int i = 0; i < m; ++i)
        cin >> x;
    if (m < n) {
        cout << x * m << endl;
        return;
    }

    cout << x * (n - 1 + (m - n + 1) % 2) << endl;
}

signed main() {
    int t;
    cin >> t;

    for (int _ = 0; _ < t; ++_)
        solve();
}
