try:
    def solve():
        n = int(input())
        lst = list(map(int,input().split()))
        sum_ = sum(lst)%n
        ans = sum_ * (n-sum_)
        print(ans)
    test = int(input())
    count = 1
    while count<=test:
        solve()
        count += 1
except EOFError:
    print(" ")


