#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
constexpr int MX = 400;
void solve(){
    int n, m;
    cin >> n >> m;
    vector <int> x(m + 1);
    for (int i = 1; i <= m; i++){
        cin >> x[i];
    }
    /*if (n >= m){
        cout << 1ll * m * x[0] << '\n';
    }
    else{
        if ((m - n) % 2 == 0){
            cout << 1ll * n * x[0] << '\n';
        }
        else{
            cout << 1ll * (n - 1) * x[0] << '\n';
        }
    }*/
    vector <vector <vector <bool>>> used(m + 1, vector <vector <bool>> (4 * MX + 1, vector <bool> (4 * MX + 1, false)));
    vector <pair <int, pair <int, int>>> dq;
    int head = 0;
    dq.push_back({0, {0, 0}});
    used[0][2 * MX][2 * MX];
    while (head != (int)dq.size()){
        pair <int, pair <int, int>> nw = dq[head++];
        int i = nw.first;
        if (i == m){
            break;
        }
        int a1 = nw.second.first;
        int a2 = nw.second.second;
        //cout << "AAA " << i << " " << a1 << " " << a2 << '\n';
        int aa1 = x[i + 1] - a1;
        int aa2 = a2;
        if (!used[i + 1][aa1 + 2 * MX][aa2 + 2 * MX]){
            dq.push_back({i + 1, {aa1, aa2}});
            used[i + 1][aa1 + 2 * MX][aa2 + 2 * MX] = true;
        }
        aa1 = a1;
        aa2 = x[i + 1] - a2;
        if (!used[i + 1][aa1 + 2 * MX][aa2 + 2 * MX]){
            dq.push_back({i + 1, {aa1, aa2}});
            used[i + 1][aa1 + 2 * MX][aa2 + 2 * MX] = true;
        }
    }
    long long res = 0;
    for (int i = 0; i <= 4 * MX; i++){
        for (int j = 0; j <= 4 * MX; j++){
            if (!used[m][i][j]){
                continue;
            }
            //cout << i - 2 * MX << " " << j - 2 * MX << '\n';
            res = i - 2 * MX + j - 2 * MX;
        }
    }
    cout << res << '\n';
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--){
        solve();
    }
}

