//#pragma GCC optimize("unroll-loops,Ofast")
//#pragma GCC target("sse,sse2,avx,avx2")

#include <bits/stdc++.h>

using namespace std;
const int inf = 1e9;

//mt19937 rnd(time(0));
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    vector<map<int, pair<int, int>>> dp(m + 1);
    dp[0][0] = {0, 0};
    for (int i = 0; i < m; ++i) {
        for (auto to: dp[i]) {
            if (dp[i + 1].count(to.first)) {
                dp[i + 1][to.first].first = min(
                        {dp[i + 1][to.first].first, a[i] - to.second.first, a[i] - to.second.second});
                dp[i + 1][to.first].second = max(
                        {dp[i + 1][to.first].second, a[i] - to.second.first, a[i] - to.second.second});
            } else {
                dp[i + 1][to.first].first = min(
                        {a[i] - to.second.first, a[i] - to.second.second});
                dp[i + 1][to.first].second = max(
                        {a[i] - to.second.first, a[i] - to.second.second});
            }
            if (dp[i + 1].count(a[i] - to.first)) {
                dp[i + 1][a[i] - to.first].first = min(
                        {dp[i + 1][a[i] - to.first].first, to.second.first, to.second.second});
                dp[i + 1][a[i] - to.first].second = max(
                        {dp[i + 1][a[i] - to.first].second, to.second.first, to.second.second});
            } else {
                dp[i + 1][a[i] - to.first].first = min({to.second.first, to.second.second});
                dp[i + 1][a[i] - to.first].second = max(
                        {to.second.first, to.second.second});
            }
        }
    }
    int ans = -inf;
    for (auto to: dp[m]) {
        ans = max(ans, to.first + to.second.second);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}
