#include <bits/stdc++.h>

#ifndef  WILEYNE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using ordered_set = __gnu_pbds::tree<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;


using ll = long long;
using ld = long double;

using namespace std;

const int MAX_N = (int) 3e5 + 100;
const double eps = acos(-1);
const int INT_INF = (int) 2e9 + 10;
const int MOD = (int) 1e9 + 7;
auto seet = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(seet);

pair<int,int> tree[4*MAX_N];
int a[MAX_N];
#define int ll
void build(int v, int l, int r){
    if(l+1==r){
        tree[v] = {0,l};
        return;
    }
    int mid = (l+r)>>1;
    build(v*2+1,l,mid);
    build(v*2+2,mid,r);
    tree[v] = min(tree[v*2+1],tree[v*2+2]);
}

void update(int v, int l, int r, int ind, int val){
    if(l+1==r){
        tree[v] = {val,l};
        a[ind] = val;
        return;
    }
    int mid = (l+r)>>1;
    if(mid<ind){
        update(v*2+1,l,mid,ind,val);
    }
    else{
        update(v*2+2,mid,r,ind,val);
    }
    tree[v] = min(tree[v*2+1],tree[v*2+2]);
}

void solve(){
    int n,m;
    cin>>n>>m;
    build(0,0,n);
    for(int i = 0;i<m;++i){
        int x;
        cin>>x;
        update(0,0,n,tree[0].second,x -tree[0].first);
    }
    ll sums = 0;
    for(int i = 0;i<n;++i){
        sums+=a[i];
    }
    cout<<sums;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef WILEYNE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }

    return 0;
}
