#include <bits/stdc++.h>

#define int long long
using namespace std;

void solve();

signed main() {
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
        cout << "\n";
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> arr(m);
    for (int i = 0; i < m; i++) {
        cin >> arr[i];
    }
    if (m <= n) {
        cout << arr[0] * m;
    } else {
        m -= n;
        cout << arr[0] * n - ((m % 2) * arr[0]);
    }
}