// tch1cherin GM!
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#pragma GCC target("avx2,tune=native")
using namespace std;

constexpr long long INF = 1e18;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int &value : x) {
      cin >> value;
    }
    reverse(x.begin(), x.end());
    vector<long long> dp(m + 1, -INF);
    dp[0] = 0;
    if (n <= 10000 && m <= 10000) {
      for (int i = 0; i < m; i++) {
        for (int j = m - 1; j >= 0; j--) {
          if (2 * j - i >= 0 && 2 * j - i <= n && 2 * (j + 1) - (i + 1) >= 0 && 2 * (j + 1) - (i + 1) <= n) {
            dp[j + 1] = max(dp[j + 1], dp[j] + x[i]);
          }
        }
      }
    } else {
      int opt = 0;
      int C = 7000;
      if (count(x.begin(), x.end(), x[0]) == m) {
        C = 200;
      }
      for (int i = 0; i < m; i++) {
        if (1.0 * clock() / CLOCKS_PER_SEC >= 1.0) {
          C = 2500;
        }
        int new_opt = max(i / 2, opt);
        long long val = -INF;
        for (int j = min(m - 1, opt + C); j >= opt - C && j >= (i + 1) / 2; j--) {
          if (2 * (j + 1) - (i + 1) <= n) {
            dp[j + 1] = max(dp[j + 1], dp[j] + x[i]);
            if (dp[j + 1] > val) {
              val = dp[j + 1];
              new_opt = j + 1;
            }
          }
        }
        opt = new_opt;
      }
    }
    long long total = accumulate(x.begin(), x.end(), 0LL);
    long long max_dp = -INF;
    for (int j = m; j >= 0; j--) {
      if (2 * j - m >= 0 && 2 * j - m <= n) {
        max_dp = max(max_dp, dp[j]);
      }
    }
    cout << 2 * max_dp - total << "\n";
  }
}
