import collections
t = int(input())

for i in range(0,t):
    n = int(input())
    cars = list(map(int, input().split()))
    cars = sorted(cars)
    x = 0
    y = n-1

    while x<=y:
        total = cars[x]+cars[y]
        cars[x] = total//2
        cars[y] = total - cars[x]

        x += 1
        y -= 1
    
    cars = sorted(cars)
    carval = []
    for key in collections.Counter(cars).keys():
        carval.append(key)

    carnum = []
    for val in collections.Counter(cars).values():
        carnum.append(val)

    incon = 0
    for x in range(0, len(carval)):
        for y in range(x+1, len(carval)):
            temp = (carval[x]-carval[y])*(carnum[x]*carnum[y])
            if temp<0:
                temp *= -1
            incon += temp

    print(incon) 