#include <bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 5e3;
int dp[maxn][maxn], a[maxn];

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    reverse(a, a + m);
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = -1e18;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= n - 1; j++) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a[i]);
        }
        for (int j = 1; j <= n; j++) {
            dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] - a[i]);
        }
    }
    int mx = 0;
    for (int i = 0; i <= n; i++) {
        mx = max(dp[m][i], mx);
    }
    fill(a, a + m, 0);
    cout << mx << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tests = 1;
    cin >> tests;
    while (tests--) solve();
}

