#include <bits/stdc++.h>

#define int long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using namespace std;

const int inf = 1e18;

void solve_case() {
    int n, m; cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }
    int ans = -inf;
    for (int mask = 0; mask < 4; mask++) {
        int sgn1 = ((mask & 1) ? 1 : -1);
        int sgn2 = ((mask & 2) ? 1 : -1);
        vector dp(2, vector<int>(2, -inf));
        dp[0][0] = 0;
        for (int i = 0; i < m; i++) {
            vector dq(2, vector<int>(2, -inf));
            dq[0][0] = max(dp[1][0] - sgn1 * x[i], dp[0][1] - sgn2 * x[i]);
            dq[0][1] = max(dp[1][1] - sgn1 * x[i], dp[0][0] + sgn2 * x[i]);
            dq[1][0] = max(dp[0][0] + sgn1 * x[i], dp[1][1] - sgn2 * x[i]);
            dq[1][1] = max(dp[0][1] + sgn1 * x[i], dp[1][0] + sgn2 * x[i]);
            dp.swap(dq);
        }
        ans = max(ans, dp[mask & 1][mask & 2]);
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve_case();
    }
}