#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define int int64_t
#define pw(x) (int64_t(1)<<x)

using namespace std;
using namespace __gnu_pbds;

typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> oset;

mt19937 gen(time(0));

const int INF = 1e18;

void solve () {
    int n, m;
    cin >> n >> m;
    int x[m];
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    vector <int> mem(m);
    int ans = -INF;
    for (int it = 0; it < 1e6; ++it) {
        for (int i = 0; i < m; ++i) {
            mem[i] = gen() % n;
        }
        vector <int> a(n);
        for (int i = 0; i < m; ++i) {
            a[mem[i]] = x[i] - a[mem[i]];
        }
        int cur = 0;
        for (auto to : a) {
            cur += to;
        }
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}

int32_t main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int q;
    cin >> q;
    while (q--) {
        solve();
    }
}
