def somar(lst):
    soma = 0
    for x in lst:
        soma += x
    return soma

t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int, input().split()))
    soma = somar(A)
    print((soma % n) * (n - soma % n))