#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
    int n, m;
    cin >> n >> m;
    vector<ll> x(m);
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }
    std::reverse(x.begin(), x.end());
    set<pair<ll, int>> dp[2];
    dp[1] = {};
    dp[0] = {{x[0], n - 1}};
    int f = 0;
    for(int i = 1; i < m; i++){
        while (!dp[f].empty()){
            auto [val, num] = *dp[f].begin();
            dp[f].erase(dp[f].begin());
            if(num > 0)
                dp[f^1].insert({val + x[i], num-1});
            if(num < n){
                dp[f^1].insert({val - x[i], num+1});
            }
        }
        while (dp[f].size() > 52){
            dp[f].erase(dp[f].begin());
        }
        f^=1;
    }
    cout << prev(dp[f].end())->first << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
/*

 */