#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdint>
using namespace std;
#define int long long

void solution();

int32_t main() {
#ifdef LOCAL
    freopen("test", "r", stdin);
    freopen("out", "w", stdout);
#endif

    int t;
    cin >> t;
    while (t--) {
        solution();
    }
}

struct rmq {
    int n;
    vector<int> t, lad;
    
    rmq(int _n) {
        t.resize(n);
    }
};

void solution() {
    int n, m;
    cin >> n >> m;

    vector<int> a(m);
    for (auto &x : a) {
        cin >> x;
    }

    reverse(a.begin(), a.end());
    
    int sm = 0;
    vector<int> d(m);
    vector<int> p(m);
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        if (cnt < n) {
            d[i] = 1;
            sm += a[i];
            cnt++;
            p[i] = cnt;
        } else {
            d[i] = 1;
            sm += a[i];
            cnt++;
            p[i] = cnt;
            int mn = -1;
            for (int j = i; p[j] > 1; --j) {
                if (d[j] == -1) continue;
                if (mn == -1 || a[j] < a[mn]) {
                    mn = j;
                }
            }
            sm -= a[mn] * 2;
            d[mn] = -1;
            for (int j = mn; j <= i; ++j) {
                p[j] = p[j - 1] + d[j];
            }
            cnt -= 2;
        }
    }

    cout << sm << '\n';
}