def track(n, A):
    a = sum(A)
    b = (int(a/n) + 1)*n - a
    c = n - b
    return b * c

for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    print(track(n, A))