// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(69); // chrono::steady_clock::now().time_since_epoch().count()
#define all(x) x.begin(), x.end()
#define int long long
#define ull unsigned long long
#define ld long double
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

const long long INF = 1e15 + 69;
const int MAXN = 2e5 + 11;

void solve() {
    int n, m, sum;
    cin >> n >> m;
    sum = 0;
    vector<int> x(m);
    multiset<int> cur_last;
    cur_last.clear();
    sum = 0;
    for (int i = 0; i < m; i++) {
        cin >> x[i];
        sum += x[i];
    }
    if (n == 1) {
        sum = 0;
        for (int i = 0; i < m; i++) {
            sum = x[i] - sum;
        }
        cout << sum << endl;
        return;
    }
    int ans = -INF;
    if (false) {
        for (int mask = 0; mask < (1 << m); mask++) {
            pair<int, int> cur_ans = {0, 0};
            for (int i = 0; i < m; i++) {
                if ((mask >> i) & 1) {
                    cur_ans.second = x[i] - cur_ans.second;
                } else {
                    cur_ans.first = x[i] - cur_ans.first;
                }
            }
            ans = max(ans, cur_ans.first + cur_ans.second);
        }
        cout << ans << endl;
    } else {
        vector<vector<int>> cur_ans(m, vector<int>(3, -INF));
        cur_ans[0][0] = x[0];
        cur_ans[0][1] = max(x[0], -x[0]);
        cur_ans[0][2] = -x[0];
        for (int i = 1; i < m; i++) {
            cur_ans[i][0] = x[i] + cur_ans[i - 1][1];
            cur_ans[i][1] = max(cur_ans[i][1], cur_ans[i - 1][2] + x[i]);
            cur_ans[i][1] = max(cur_ans[i][1], cur_ans[i - 1][0] - x[i]);
            cur_ans[i][2] = max(cur_ans[i][2], cur_ans[i - 1][1] - x[i]);
        }
        cout << cur_ans[m - 1][0] << endl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
