import math

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    sumx = sum(a)
    x = sumx//n
    m=0
    if sumx%n==0:
        for i in range(n):
            a[i] = x
    else:
        for i in range(n):
            a[i] = x
        m = sumx%n


    print(m*(n-m))



