#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll inf = 1e18;

void solveEq(int n, int m, vector<ll>& x) {
    ll s = x[0] * (min(n, m) - max(m - n, 0) % 2);
    cout << s << '\n';
}

void solveN2(int n, int m, vector<ll>& x) {
    vector<vector<ll>> dp(2, vector<ll>(2, -inf)), dp2(2, vector<ll>(2, -inf));
    if (m % 2 == 0) {
        dp[0][0] = dp[1][1] = 0;
    } else {
        dp[0][1] = dp[1][0] = 0;
    }
    for (int i = 0; i < m; ++i) {
        dp2[0][0] = max(dp[0][1] + x[i], dp[1][0] + x[i]);
        dp2[1][1] = max(dp[0][1] - x[i], dp[1][0] - x[i]);
        dp2[0][1] = max(dp[1][1] + x[i], dp[0][0] - x[i]);
        dp2[1][0] = max(dp[1][1] + x[i], dp[0][0] - x[i]);
        dp = dp2;
    }
    cout << dp2[0][0] << '\n';
}

void solveNM(int n, int m, vector<ll>& x) {
    vector<ll> dp(n + 1, -inf), dp2(n + 1, -inf);
    for (int i = 0; i <= n; ++i) {
        if (m % 2 == (n + i) % 2) {
            dp[i] = 0;
        }
    }
    for (int i = 0; i < m; ++i) {
        dp2.assign(n + 1, -inf);
        for (int j = 0; j <= n; ++j) {
            if (j < n) {
                dp2[j] = max(dp2[j], dp[j + 1] - x[i]);
            }
            if (j > 0) {
                dp2[j] = max(dp2[j], dp[j - 1] + x[i]);
            }
        }
        dp = dp2;
    }
    cout << dp[n] << '\n';
}

void solvePos(int n, int m, vector<ll>& x) {
    cout << -1 << '\n';
}
const ll NMMAX = 1e8;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }

    if (n == 2) {
        solveN2(n, m, x);
        return;
    }

    bool eq = true;
    for (int i = 0; i < m; ++i) {
        if (x[i] != x[0]) {
            eq = false;
        }
    }
    if (eq) {
        solveEq(n, m, x);
        return;
    }

    if (ll(n) * m <= NMMAX) {
        solveNM(n, m, x);
        return;
    }



    bool pos = true;
    for (int i = 0; i < m; ++i) {
        if (x[i] < 0) {
            pos = false;
        }
    }
    if (pos) {
        solvePos(n, m, x);
        return;
    }

    cout << "-1\n";
}

void start() {
    int t;
    cin >> t;
    while (t--) solve();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    start();
}
