#include <iostream>
#include <set>
#include <vector>
#include <random>
#include <iomanip>
//#include <fstream>
#include <algorithm>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
#define int long long
const int INF = 1e18;
signed main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int q;
    cin >> q;
    while (q--) {
        int n, m;
        cin >> n >> m;
        vector<int> x(m);
        for (int i = 0; i < m; i++) {
            cin >> x[i];
        }
        if (m <= n) {
            cout << x[0] * n << '\n';
        }
        else {
            int ost = m - n;
            if (ost % 2 == 0) {
                cout << x[0] * (n - 1);
            }
            else {
                cout << x[0] * n;
            }
            cout << '\n';
        }
    }
}