#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
//    vector<vector<int>> dp(m + 1, vector<int>(n + 1, -1e17));
    vector<int> new_sloy(n + 1, -1e17), sloy(n + 1, -1e17);
    sloy[n] = 0;
    for (int i = m - 1;i > -1; i--) {
        for (int j = max(0ll, n - (m - i)); j <= n; j++) {
            if (j < n) {
                new_sloy[j] = max(new_sloy[j], a[i] + sloy[j + 1]);
            }
            if (j > 0) {
                new_sloy[j] = max(new_sloy[j], -a[i] + sloy[j - 1]);
            }
        }
        sloy = new_sloy;
        new_sloy.assign(n + 1, -1e17);
    }
    int mx = -1e17;
    for (auto el : sloy) {
        mx = max(mx, el);
    }
    cout << mx << "\n";
}

signed main() {
    int t;
    cin >> t;
    while (t--) solve();
}
