#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("02")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
/*int gcd(int a, int b, int &x, int &y){
    //cout << a << " " << b << "\n";
    if (a == 0){
        x = 0y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b % a, a, x1, y1);
    x = y1 - b / a * x1;
    y = x1;
    return d;
}*/
const int inf = 1e9 + 7;
const int N = 400 * 400 + 3;
void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m + 1);
    for (int i = 1; i <= m; i++){
        cin >> x[i];
    }
    vector<pair<int, int>> dp1(N, {inf, -inf}), dp2(N, {inf, -inf});
    dp1[0] = {0, 0};
    for (int i = 1; i <= m; i++){
        vector<pair<int, int>> now1(N, {inf, -inf}), now2(N, {inf, -inf});
        for (int a= 0 ; a < N; a++){
            if (dp1[a].first == inf){
                continue;
            }
            int mn = min(x[i] - dp1[a].second, x[i] - dp1[a].first);
            int mx = max(x[i] - dp1[a].first, x[i] - dp1[a].second);
            now1[a] = {min(now1[a].first, mn), max(now1[a].second, mx)};
            if (x[i] - a >= 0){
                now1[x[i] - a]= {min(now1[x[i] - a].first, dp1[a].first), max(now1[x[i] - a].second, dp1[a].second)};
            } else {
                now2[-(x[i] - a)] = {min(now2[-(x[i] - a)].first, dp1[a].first), max(now2[-(x[i] - a)].second, dp1[a].second)};
            }
        }
        for (int a= 0 ; a < N; a++){
            if (dp2[a].first == inf){
                continue;
            }
            int mn = min(x[i] - dp2[a].second, x[i] - dp2[a].first);
            int mx = max(x[i] - dp2[a].first, x[i] - dp2[a].second);
            now2[a] = {min(now2[a].first, mn), max(now2[a].second, mx)};
            if (x[i] + a >= 0){
                now1[x[i] + a]= {min(now1[x[i] + a].first, dp2[a].first), max(now1[x[i] + a].second, dp2[a].second)};
            } else {
                now2[-(x[i] + a)] = {min(now2[-(x[i] + a)].first, dp2[a].first), max(now2[-(x[i] + a)].second, dp2[a].second)};
            }
        }
        dp1 = now1;
        dp2 = now2;

    }
    int res = -inf;
    for (int a = 0; a < N; a++){
        res = max(res, a+ dp1[a].second);
        res = max(res, -a + dp2[a].second);
    }
    cout << res << "\n";
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--){
        solve();
    }


}
