#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl '\n'
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()

#ifdef local
#define dbg(x) cout << __LINE__ << " : " << (#x) << " = " << x << endl;
#else
#pragma GCC optimize("03")
    #define dbg(x) ;
#endif

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }
    if (m > 30) return;
    int ans = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        int add = 0, sub = 0, cnt = 0, sum = 0, bad = 0;
        for (int i = m - 1; i >= 0; i--) {
            int bit = (1ll << i) & mask;
            if (bit) {
                if (sub) {
                    sub--;
                    add++;
                } else {
                    add++;
                    cnt++;
                }
                sum += x[i];
            } else {
                if (add) {
                    add--;
                    sub++;
                } else {
                    bad++;
                }
                sum -= x[i];
            }
        }
        if (!bad && cnt <= n) {
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef local
    freopen("in.txt", "r", stdin);
#endif
    int test;
    cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
