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

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n, m;
        cin >> n >> m;

        vector<long long> a(n, 0), b(m);
        for (int i = 0; i < m; ++i) {
            cin >> b[i];
        }

        set<pair<long long, pair<int, vector<long long>>>> q;

        set<pair<int, vector<long long>>> visited;
        visited.insert({0, a});
        q.insert({0, {0, a}});

        long long ans = -1e18;
        while (!q.empty()) {
            long long sum = -q.begin()->first;
            int it = q.begin()->second.first;
            vector<long long> c = q.begin()->second.second;
            q.erase(q.begin());

            if (it == m) {
                ans = sum;
                break;
            }

            for (int i = 0; i < n; ++i) {
                sum -= c[i];
                c[i] = b[it] - c[i];
                sum += c[i];
                
                if (!visited.count({it + 1, c})) {
                    visited.insert({it + 1, c});
                    q.insert({-sum, {it + 1, c}});
                }
                
                sum -= c[i];
                c[i] = b[it] - c[i];
                sum += c[i];
            }
        }

        cout << ans << "\n";
    }

    return 0;
}
