any=1
def get():
    str = input()
    a= str.split( ) 
    b=[]
    for i in range(0,len(a)):
        b.append(int(a[i]))
    if len(b)==1:
        return(b[0])
    else:
        return b
def getarray():
    str = input()
    a= str.split( ) 
    b=[]

    for i in range(0,len(a)):
        b.append(int(a[i]))
    return b
def cout(a):
    for i in range(len(a)-1):
        temp=str(a[i])
        print(temp, end =" ")
    print(str(a[len(a)-1]))


c=get()
for i in range(c):
    n=get()
    a=getarray()
    sume=0
    re=0
    for x in a:
        sume=sume+x
    

    if sume%n==0:
        print("0")
    else:
        re=sume%n
        print((n-re)*re)
