#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using li = __int128;
using db = double;
using ld = long double;
using pi = pair <int, int>;
using pll = pair <ll, ll>;
#define all(x) x.begin(), x.end()

const ll INFll = 3e14;

mt19937 rnd(time(NULL));

struct V {
    db x;
    db y;
};

V operator+ (const V& a, const V& b) {
    return {a.x + b.x, a.y + b.y};
}
db operator* (const V& a, const V& b) {
    return a.x * b.x + a.y * b.y;
}
db operator^ (const V& a, const V& b) {
    return a.x * b.y - a.y * b.x;
}
V operator* (const V& a, db k) {
    return {a.x * k, a.y * k};
}

ll bin_pow(ll a, ll s, ll mod) {
    ll res = 1;
    while (s) {
        if (s & 1) {
            res *= a;
            res %= mod;
        }
        a = (a * a) % mod;
        s >>= 1;
    }
    return res;
}


void solve() {
    int n, m;
    cin >> n >> m;
    vector <ll> v(m);
    set <int> st;
    for (auto& i : v) cin >> i, st.insert(i);
    reverse(all(v));
    int bal = 0;
    ll sum = 0;
    int l = 0;
    int ball = 0;
    for (int i = 0; i < n; ++i) {
        sum += v[i];
        ++bal;
        if (bal > n) {
            while (l < i && v[l] != *st.begin()) {
                ++l;
                ++ball;
            }
            --bal;
            --ball;
            sum -= 2 * v[l];
            if (ball == 0) ++l, ++ball;
        }
    }


    cout << sum << '\n';
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
