#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
// #include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());

using ll = long long;
using ld = long double;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ttt;
    cin >> ttt;
    while (ttt--) {
        int n, m;
        cin >> n >> m;
        vector <ll> x(m);
        for (int i=0; i < m; ++i) {
            cin >> x[i];
        }
        ll ans = 0;
        if (m <= n) {
            cout << x[0] * m << "\n";
            continue;
        }
        m -= n;
        ans += x[0] * n;
        ans -= x[0] * (m % 2);
        cout << ans << "\n";
    }
    return 0;
}
