#include <bits/stdc++.h>

using ll = long long;
using namespace std;

int main() {
    ll t;
    cin >> t;
    for (ll ti = 0; ti < t; ++ti) {
        ll n, m;
        cin >> n >> m;
        ll x;
        for (ll i = 0; i < m; ++i) cin >> x;
        if (m <= n) cout << m * x << endl;
        else if (n % 2 == m % 2) cout << n * x << endl;
        else cout << n * x - x << endl;
    }
}