#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PI;

#define SI(x) scanf("%d", &x)
#define SLL(x) scanf("%lld", &x)
#define SORTV(v) sort(v.begin(), v.end())
#define EACH(it, v) for(__typeof(v.begin()) it(v.begin()); it != v.end(); it++)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define f first
#define s second

template<class T> void print_array(T a[], int size) { for(int i=0; i<size; i++) cout<<a[i]<<" "; cout<<endl; }

template<class T> void print_array_v(T &a) { int size = a.size(); for(int i=0; i<size; i++) cout<<a[i]<<" "; cout<<endl; }

int main()
{
	int T;
	scanf("%d", &T);
	assert(T<=10);
	while(T--)
	{
		int n; SI(n); assert(n<=1e3);
		int a[1010];
		for(int i=0; i<n; i++)
		{
			SI(a[i]);
			assert(a[i] <= 1e6);
		}
		sort(a, a+n);
		int sum = 0;
		for(int i=0; i<n/2; i++)
			sum += a[n-i-1] - a[i];
		cout<<sum<<endl;
	}
	return 0;
}