#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBMTDsKdHlwZWRlZiB1bnNpZ25lZCBsb25nIGxvbmcgVUxMOwp0eXBlZGVmIHZlY3RvcjxpbnQ+IFZJOwp0eXBlZGVmIHZlY3RvcjxMTD4gVkxMOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IFBJOwoKI2RlZmluZSBTSSh4KSBzY2FuZigiJWQiLCAmeCkKI2RlZmluZSBTTEwoeCkgc2NhbmYoIiVsbGQiLCAmeCkKI2RlZmluZSBTT1JUVih2KSBzb3J0KHYuYmVnaW4oKSwgdi5lbmQoKSkKI2RlZmluZSBFQUNIKGl0LCB2KSBmb3IoX190eXBlb2Yodi5iZWdpbigpKSBpdCh2LmJlZ2luKCkpOyBpdCAhPSB2LmVuZCgpOyBpdCsrKQojZGVmaW5lIHBiKHgpIHB1c2hfY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