#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) {
    dp11[ind + 1][i + INF] = max(dp11[ind + 1][i + INF], i + j);
    dp01[ind + 1][i + INF] = max(dp01[ind + 1][i + INF], i - j);
    dp10[ind + 1][i + INF] = max(dp10[ind + 1][i + INF], j - i);
    dp00[ind + 1][i + INF] = max(dp00[ind + 1][i + INF], -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, vector<int> (2 * INF, -INF)), dp10 = dp11, dp01 = dp10, dp00 = dp01, ven = dp00;
    dp11[0][INF] = 0;
    dp10[0][INF] = 0;
    dp01[0][INF] = 0;
    dp00[0][INF] = 0;
//    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);
//        }

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

    int ans = -INF * 2;
    for (int i = -INF; i < INF; ++i) {
        ans = max(ans, dp11[m][i + INF]);
    }
    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();
    }
}
