#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;

using ordered_set = tree<int, null_type, less < int>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
istream &operator>>(istream &is, vector <T> &vec) {
      for (auto &elem: vec) is >> elem;
      return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector <T> &vec) {
      for (auto &elem: vec) os << elem << ' ';
      os << '\n';
      return os;
}

//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma optimize("avx, avx2")

const int NOTH = 0;

struct Node {
      int val, tag;

      Node(int val = 0, int tag = NOTH) : val(val), tag(tag) {}

      void apply(int v, int l, int r) {
            val += (r - l) * v;
            tag += v;
      }

      friend Node operator+(const Node &x, const Node &y) {
            return {x.val + y.val, NOTH};
      }
};

struct Lazy_Segtree {
      int size;
      vector <Node> tree;

      Lazy_Segtree(int n) {
            size = 1;
            while (size < n) size <<= 1;
            tree.resize(size << 1, Node());
      }

      Lazy_Segtree(const vector<int> &a) : Lazy_Segtree(a.size()) {
            for (int i = 0; i < a.size(); ++i) tree[i + size] = a[i];
            for (int i = size - 1; i > 0; --i) tree[i] = tree[i << 1] + tree[i << 1 | 1];
      }

      void push(int x, int lx, int rx) {
            if (rx - lx == 1 or tree[x].tag == NOTH) return;

            int mid = (lx + rx) >> 1;
            tree[x << 1].apply(tree[x].tag, lx, mid);
            tree[x << 1 | 1].apply(tree[x].tag, mid, rx);

            tree[x].tag = NOTH;
      }

      void set(int l, int r, int v, int x, int lx, int rx) {
            push(x, lx, rx);
            if (rx <= l or r <= lx) return;
            if (l <= lx and rx <= r) tree[x].apply(v, lx, rx);
            else {
                  int mid = (lx + rx) >> 1;

                  set(l, r, v, x << 1, lx, mid);
                  set(l, r, v, x << 1 | 1, mid, rx);

                  tree[x] = tree[x << 1] + tree[x << 1 | 1];
            }
      }

      Node get(int l, int r, int x, int lx, int rx) {
            push(x, lx, rx);
            if (rx <= l or r <= lx) return Node();
            if (l <= lx and rx <= r) return tree[x];
            else {
                  int mid = (lx + rx) >> 1;

                  Node s1 = get(l, r, x << 1, lx, mid);
                  Node s2 = get(l, r, x << 1 | 1, mid, rx);

                  return s1 + s2;
            }
      }

      void set(int l, int r, int v) {
            set(l, r, v, 1, 0, size);
      }

      Node get(int l, int r) {
            return get(l, r, 1, 0, size);
      }
};

int dgcd(int a, int b, int &x, int &y) {
      if (a == 0) {
            x = 0, y = 1;
            return b;
      }

      int x1, y1;
      int d = dgcd(b % a, a, x1, y1);
      x = y1 - (b / a) * x1;
      y = x1;

      return d;
}

#define int long long

void solve() {
      int n, m;
      cin >> n >> m;
      vector<int> qs(m);
      cin >> qs;
      map<int, int, greater<int>> cnt;
      for (int i = 0; i < m; ++i) cnt[qs[i]]++;

      int ost = n;
      int res = 0;
      int cnty = -1, lastx = -1e18;
      for (auto &[x, y]: cnt) {
            if (y < ost) {
                  ost -= y;
                  res += x * y;
            } else {
                  res += x * (ost - 1);
                  y -= (ost - 1);
                  ost = 1;
                  cnty = y;
                  lastx  = x;
                  break;
            }
      }
      int val = 0;
      for (int i = 0; i < m; ++i) {
            if (qs[i] > lastx) {
                  continue;
            }

            if (qs[i] == lastx) {
                  if (cnty) {
                        cnty--;
                        val = qs[i] - val;
                  }
                  continue;
            }

            val = qs[i] - val;
      }

      cout << res + val << endl;
}

signed main() {
#ifdef LOCAL
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
#else
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
#endif
      int t;
      cin >> t;
      while (t--) solve();
}