#include<bits/stdc++.h>

#define int long long

using namespace std;

const int INF = 2e9;

int solve4() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    int start = 0;
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    if (m <= n) {
        return x[0] * m;
    }
    int t = m - n;
    if (t % 2 == 1) {
        return x[0] * (n - 1);
    }
    return x[0] * n;
}

int solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
        sum += x[i];
    }
    /*if (m <= n) {
        return sum;
    }*/
    vector<int> dp(n + 1);
    for (int j = 0; j < m; ++j) {
        vector<int> ndp(n + 1, -INF);
        int u = min(n, 100ll);
        for (int i = 1; i < u + 1; ++i) {
            ndp[i - 1] = max(ndp[i - 1], dp[i] + x[j]);
        }
        for (int i = 0; i < u; ++i) {
            ndp[i + 1] = max(ndp[i + 1], dp[i] - x[j]);
        }
        dp = ndp;
    }
    return dp[0];
}

signed main() {
    int _;
    cin >> _;
    while (_--) {
        cout << solve() << endl;
    }
    return 0;
}
