def process(A):
    n = len(A)
    S = sum(A)
    x = S % n
    return (n-x)*x
    

t = int(input())
for i in range(t):
    n = int(input())
    A = [int(x) for x in input().split()]
    print(process(A))