#include <iostream>
#include <vector>
using namespace std;


const long long INF = 1e16;


void solve() {
	long long n, m, ans, x;
	cin >> n >> m;
	for (long long i = 0; i < m; i++)
        cin >> x;
	if (n >= m) {
        ans = x * m;
	} else {
        ans = x * n;
        if ((m - n) % 2 == 1)
            ans -= x;
	}
	cout << ans << '\n';
}


int main() {
	long long t;
	cin >> t;
	for (long long i = 0; i < t; i++)
		solve();
}

