import math
import sys


def scan():
    return list(map(int, sys.stdin.readline().strip().split()))


def solution():
    for _ in range(int(input())):
        n = int(input())
        a = scan()
        a = sorted(a)
        for i in range(n//2):
            d = a[i] + a[n-1-i]
            if d % 2 == 1:
                d = math.ceil(d/2)
                a[n-1-i] = d
                a[i] = d-1
            else:
                d //= 2
                a[n-1-i] = d
                a[i] = d
        s = sum(a)
        d = 0
        for i in range(n):
            d += abs(s - (n-i)*(a[i]))
            s -= a[i]
        print(d)


if __name__ == '__main__':
    solution()
