#ifndef LOCAL
#pragma GCC optimize("O3")
#endif

#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;
using oset = tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
const ll nMax = 2100;
ll dp[nMax][nMax];

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    int eq[2]={0,0};
    for(auto&o : x) cin >> o;
    set<int> aaa;
    for(auto o : x) aaa.insert(o);
    for(auto o : x){
        auto &u = eq[o!=*aaa.begin()];
        auto &u1 = eq[o==*aaa.begin()];
        bool good = o==*aaa.begin();
        if(u + u1 < n){
            u++;
            continue;
        }
        if(!good && u1){
            u1--;
            u++;
            continue;
        }
        u1++;
        u--;
        continue;
    }
    cout << eq[0] * *aaa.begin() + eq[1] * *aaa.rbegin() << '\n';
}

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