#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <chrono>
#include <random>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <set>
#define endl '\n'

using namespace std;
using i64 = long long;
using ld = long double;

const i64 INF = 1e18 + 5;

mt19937 rnd(29);

const i64 S = 3e5 + 10;
i64 a[S];

int main() {
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	i64 t; cin >> t;

	while (t--) {
		i64 n, m; cin >> n >> m;
		bool check = true;
		for (i64 x = 1; x <= m; ++x) {
			cin >> a[x];
			if (x > 1 && (a[x] != a[x - 1] || a[x] < 0)) check = false;
		}
		if (check) {
			i64 k = m / n;
			if (n >= m) {
				cout << a[1] * m << endl;
			}
			else if (k % 2 == 0) {
				cout << a[1] * (m % n) << endl;
			}
			else {
				cout << a[1] * (n - m % n) << endl;
			}
		}
	}

}