#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<iostream>
#include<math.h>
#include <map>
#include<set>
#define ll long long
#define mid ((l+r)>>1)
#define ls k<<1
#define rs (k<<1)+1
using namespace std;
const int maxn=2e5+10;
const ll inf=1e12;
ll ai[maxn];
ll dp[maxn];
ll get(int a){
ll ans=(ll)ai[a]+ai[a-1]-ai[a-2]+ai[a-3]-ai[a-4]-ai[a-5];
return ans;
}
ll get1(int a){
return (ll)ai[a]+ai[a-1]-ai[a-2]-ai[a-3];
}
int main( ){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for(int a=1;a<=n;a++) scanf("%lld",&ai[a]);
sort(ai+1,ai+n+1);
ll ans=0;
for(int a=1;a<=n;a+=2) ans+=(ai[a+1]-ai[a]);
for(int a=1;a<=n;a++) dp[a]=inf;
dp[4]=get1(4);
for(int a=6;a<=n;a+=2){
ll ans1=get(a)+dp[a-6];
ll ans2=dp[a-4]+get1(a);
dp[a]=min(ans1,ans2);
}
ans+=dp[n];
printf("%lld\n",ans);
}
}