#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 160003;

void lessgo(vector<vector<int>> &dp11, vector<vector<int>> &dp10, vector<vector<int>> &dp01, vector<vector<int>> &dp00,
            int i, int j, int ind, vector<int> &ven) {
    int i1 = lower_bound(ven.begin(), ven.end(), i) - ven.begin();
    dp11[ind + 1][i1] = max(dp11[ind + 1][i1], i + j);
    dp01[ind + 1][i1] = max(dp01[ind + 1][i1], i - j);
    dp10[ind + 1][i1] = max(dp10[ind + 1][i1], j - i);
    dp00[ind + 1][i1] = max(dp00[ind + 1][i1], -i - j);
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }

    vector<vector<int>> dp11(m + 1), dp10 = dp11, dp01 = dp10, dp00 = dp01, ven = dp00;
    dp11[0] = {0};
    dp10[0] = {0};
    dp01[0] = {0};
    dp00[0] = {0};
    ven[0] = {0};
    for (int ind = 0; ind < m; ++ind) {
        set<int> venom;
        for (int i = 0; i < ven[ind].size(); ++i) {
            venom.insert(ven[ind][i]);
            venom.insert(x[ind] - ven[ind][i]);
        }
        for (int v : venom) {
            ven[ind + 1].push_back(v);
        }
        dp11[ind + 1].resize(ven[ind + 1].size(), -INF);
        dp10[ind + 1].resize(ven[ind + 1].size(), -INF);
        dp01[ind + 1].resize(ven[ind + 1].size(), -INF);
        dp00[ind + 1].resize(ven[ind + 1].size(), -INF);

        for (int i = 0; i < ven[ind].size(); ++i) {
            if (dp11[ind][i] != -INF) {
                int i1 = ven[ind][i], j = dp11[ind][i] - i1;
                lessgo(dp11, dp10, dp01, dp00, x[ind] - i1, j, ind, ven[ind + 1]);
                lessgo(dp11, dp10, dp01, dp00, i1, x[ind] - j, ind, ven[ind + 1]);
            }
            if (dp01[ind][i] != -INF) {
                int i1 = ven[ind][i], j = i1 - dp01[ind][i];
                lessgo(dp11, dp10, dp01, dp00, x[ind] - i1, j, ind, ven[ind + 1]);
                lessgo(dp11, dp10, dp01, dp00, i1, x[ind] - j, ind, ven[ind + 1]);
            }
            if (dp00[ind][i] != -INF) {
                int i1 = ven[ind][i], j = -i1 - dp00[ind][i];
                lessgo(dp11, dp10, dp01, dp00, x[ind] - i1, j, ind, ven[ind + 1]);
                lessgo(dp11, dp10, dp01, dp00, i1, x[ind] - j, ind, ven[ind + 1]);
            }
        }
    }

    int ans = -INF * 2;
    for (int vynom : dp11[m]) {
        ans = max(ans, vynom);
    }
    cout << ans << '\n';
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}
