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

    l.sort()
    i = 0 
    j = n-1

    while i<=j:
        k = l[i]+l[j]

        if(k%2==0):
            l[i] = int(k/2)
            l[j] = int(k/2)
        else:
            l[i] = int(k/2)
            l[j] = int(k/2) +1
        i = i+1
        j = j-1

    count = 0
    for i in range(0,n):
        for j in range(i,n):
            count = count + abs(l[i] - l[j])
    
    print(count)

    