#include <bits/extc++.h>

#define int long long

using namespace std;

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}