//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#pragma GCC target("avx2")

using namespace std;

typedef long long ll;

const ll INF = 1'000'000'000'000'000'000, K = 300;

template<typename T>
bool assign_max(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool assign_min(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

vector<ll> merge(vector<ll> a, vector<ll> b) {
	vector<ll> ans(a.size() + b.size() - 1);
	ans[0] = a[0] + b[0];
	ans[1] = a[1] + b[0];
	ll u1 = 0, u2 = 0;
	for (ll i = 2; i < ans.size(); i += 2) {
		if (u2 + 2 >= b.size() || (u1 + 2 < a.size() && a[u1 + 2] - a[u1] > b[u2 + 2] - b[u2])) {
			ans[i] = ans[i - 2] + a[u1 + 2] - a[u1];
			u1 += 2;
		} else {
			ans[i] = ans[i - 2] + b[u2 + 2] - b[u2];
			u2 += 2;
		}
	}
	u1 = 1;
	u2 = 0;
	for (ll i = 3; i < ans.size(); i += 2) {
		if (u2 + 2 >= b.size() || (u1 + 2 < a.size() && a[u1 + 2] - a[u1] > b[u2 + 2] - b[u2])) {
			ans[i] = ans[i - 2] + a[u1 + 2] - a[u1];
			u1 += 2;
		} else {
			ans[i] = ans[i - 2] + b[u2 + 2] - b[u2];
			u2 += 2;
		}
	}
	return ans;
}

void solve() {
	ll n, m;
	cin >> n >> m;
	vector<ll> arr(m);
	for (ll i = 0; i < m; i++) {
		cin >> arr[i];
	}
	vector<ll> dp(n + 1, 0);
	vector<ll> now;
	ll ost = m;
	for (auto i : arr) {
		ost--;
		now.push_back(i);
		if (now.size() == K || ost == 0) {
			vector<ll> sm;
			for (ll i = now.size(); i <= n - (ll)now.size(); i++) {
				sm.push_back(dp[i]);
			}
			vector<ll> ndp(n + 1, -INF);
			multiset<ll> ns;
			ll ncol = now.size() * 2;
			ll nsum = 0;
			vector<ll> add(now.size() * 2 + 1, -INF);
			for (auto i : now) {
				ns.insert(i);
				nsum += i;
				ndp[0] = dp[1] - i;
				ndp[n] = dp[n - 1] + i;
				for (ll j = 1; j < min(n, (ll)now.size() * 2); j++) {
					ndp[j] = max(dp[j - 1] + i, dp[j + 1] - i);
				}
				for (ll j = max(1ll, n - (ll)now.size() * 2); j < n; j++) {
					ndp[j] = max(dp[j - 1] + i, dp[j + 1] - i);
				}
				swap(dp, ndp);
			}
			now.clear();
			if (sm.size() < 2) {
				continue;
			}
			add[ncol] = nsum;
			while (!ns.empty()) {
				nsum -= *ns.begin() * 2;
				ncol -= 2;
				ns.erase(ns.begin());
				add[ncol] = nsum;
			}
			sm = merge(sm, add);
			for (ll i = 0; i < sm.size(); i++) {
				assign_max(dp[i], sm[i]);
			}
		}
	}
	cout << dp.back() << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) {
		solve();
	}
}
