t=int(input())
m=[]
for i in range(t):
    s=0
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    for i in range(n//2):
        if abs(a[i]-a[n-i-1])%2!=0:
            a[i],a[n-i-1]=a[i]+(abs(a[i]-a[n-i-1]))//2,a[n-i-1]-(abs(a[i]-a[n-i-1]))//2
        else:
            a[i],a[n-i-1]=a[i]+(abs(a[i]-a[n-i-1]))/2,a[n-i-1]-(abs(a[i]-a[n-i-1]))/2
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            s+=abs(a[i]-a[j])
    m+=[s]
for i in m:
    print(int(i))
