def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def msi(): return map(str,input().split())
def li(): return list(mi())

t=ii()
for _ in range(t):
        n=ii()
        a=li()
        #a.sort()
        res=sum(a)//n
        rem=sum(a)-(res*n)
        
        print((n-rem)*rem)