for q in range(int(input())):
    n=int(input())
    l1=list(map(int,input().split()))
    l1.sort()
    for i in range(n):
        k=l1[i]+l1[n-i-1]
        if(k%2==0):
            l1[i]=k//2
            l1[n-1-i]=k//2
        else:
            l1[i]=k//2
            l1[n-i-1]=(k//2)+1
    ans=0
    l1.sort()
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=abs(l1[i]-l1[j])
    print(ans)