#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <bitset>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define for0(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
#define fora(i, v) for (auto i : v)
#define ft first
#define sd second
#define pk push_back
#define pok pop_back
#define ret return
#define con continue
#define sz(v) v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using pll = pair <ll, ll>;
using vll = vector <ll>;
using vpll = vector <pll>;
using vvll = vector <vll>;
using pi = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pi>;
using vvi = vector <vector <int>>;

const ll N = 3e5, inf = 1e18;

ll t, n, m, a, ans;
pll p1, p2;

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ans = -inf; p1 = { -1, -1 }; p2 = { -1, -1 };
		for0(q, m) {
			cin >> a;
			if (p1.ft == -1)
				p1 = { a, 1 };
			else if (p1.ft == a)
				p1.sd++;
			else if (p2.ft == -1)
				p2 = { a, 1 };
			else
				p2.sd++;
		}
		if (p2.ft == -1) {
			if (n >= m)
				ans = p1.ft * m;
			else if ((m - n) % 2 == 0)
				ans = p1.ft;
			else
				ans = p1.ft * (n - 1);
		}
		else {
			if (p1.ft < p2.ft)
				swap(p1, p2);
			if (n >= m)
				ans = p1.ft * p1.sd + p2.ft * p2.sd;
			else {
				if (p1.sd <= n - 1) {
					ans = p1.ft * p1.sd;
					ans += p2.ft * (n - p1.sd - 1);
					p2.sd -= n - p1.sd - 1; p1.sd = 0;
				}
				else {
					ans = p1.ft * (n - 1); p1.sd -= (n - 1);
				}
				p1.sd = p1.sd % 2; p2.sd = p2.sd % 2;
				if (p1.sd == 0 && p2.sd != 0)
					ans += p2.ft;
				else if (p1.sd != 0 && p2.sd == 0)
					ans += p1.ft;
				else if (p1.sd != 0 && p2.sd != 0)
					ans += p1.ft - p2.ft;
			}
		}
		cout << ans << "\n";
	}
	ret 0;
}