import math

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()

    for i in range(len(a)//2):
        x = a[i] + a[len(a)-1-i]
        if x%2==0:
            a[i],a[len(a)-1-i] = x//2,x//2
        else:
            a[i],a[len(a)-1-i] = math.floor(x/2),math.ceil(x/2)

    s=0
    for i in range(len(a)):
        for j in range(i,len(a)):
            s = s + abs(a[i]-a[j])
    print(s)



