#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++) cin >> x[i];
    reverse(x.begin(), x.end());
    vector<vector<int>> dp(m + 1, vector<int>(n + 1, -INT_MAX));
    dp[0][0] = 0;
    for (int i = 1; i <= m; i++) {
        int val = x[i - 1];
        if (val >= 0) {
            for (int j = 0; j < n; j++) {
                if (dp[i - 1][j] != -INT_MAX) {
                    dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + val);
                }
            }
            /*
            if (dp[i - 1][1] != -INT_MAX) {
                dp[i][0] = dp[i - 1][1] - val;
            }
             */
            for (int j = 1; j <= n && j <= 5; j++) {
                if (dp[i - 1][j] != -INT_MAX) {
                  //  if (j > 1 && dp[i][j - 1] < dp[i - 1][j] - val) {
                    //    cerr << i << ' ' << j - 1 << endl;
                  //  }
                    dp[i][j - 1] = max(dp[i][j - 1], dp[i - 1][j] - val);
                }
            }
        }



    }
    int ans = -INT_MAX;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, dp[m][i]);
    }
    cout << ans << '\n';
}
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
