//#pragma GCC optimize("O3, unroll_loops")
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#define int long long

using namespace std;

const int INF = 2e15, CNST = 1e5;

void solve() {
	int n, m;
	cin >> n >> m;
	vector <int> brr(m);
	set <int> st;
	for (int i = 0; i < m; i++) {
		cin >> brr[i];
		st.insert(brr[i]);
	}
	if (st.size() == 1) {
		if (m <= n) {
			cout << brr[0] * m << '\n';
		}
		else {
			int ans = brr[0] * n;
			if ((m - n) % 2 == 1) {
				ans -= brr[0];
			}
			cout << ans << '\n';
		}
		return;
	}
	vector <int> arr(n, 0);
	for (int i = 0; i < m; i++) {
		int maxi = -INF, ind = 0;
		for (int j = 0; j < n; j++) {
			if (maxi < brr[i] - arr[j] - arr[j]) {
				maxi = brr[i] - arr[j] - arr[j];
				ind = j;
			}
		}
		arr[ind] = brr[i] - arr[ind];
	}
	int ans = 0;
	for (auto elem : arr) {
		ans += elem;
	}
	cout << ans << '\n';
}

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