def solve(n, a):
    t = sum(a)
    avg = t//n
    f = t-(avg*n)
    s = n-f
    return f*s


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