import math
from collections import defaultdict,Counter

for _ in range(int(input())):
    n=int(input())
    d=defaultdict(list)
    l=list(map(int,input().split()))
    l.sort()
    
    
    for i in range(n//2):
        x=math.ceil((l[i]+l[n-i-1])/2)
        y=math.floor((l[i]+l[n-i-1])/2)
        l[i]=x
        l[n-i-1]=y

    
    l.sort()
    for i in range(n//2):
        x=math.ceil((l[i]+l[n-i-1])/2)
        y=math.floor((l[i]+l[n-i-1])/2)
        l[i]=x
        l[n-i-1]=y
    c=Counter(l)
    flag=0
    l.sort()
    
    for j in range(n-1):
        s=0
        

        for k in range(j+1,n):
            if l[j] in d:

                flag=1
                
                break
            else:
                flag=0
                s+=abs(l[k]-l[j])

        if flag==0:
            d[l[j]]=s*c[l[j]]
            
     
    
    print(sum(d.values()))
        

                
        


            
    



