#   AUTHOR : Siddhant Tohan
# "I guess,as long as I have life,all I can do is fight with all my might"
from math import ceil
if __name__== "__main__":
    for _ in range(int(input())):
        n=int(input())
        vals=list(map(int,input().split()))
        temp=sum(vals)
        if n==1:
            print(0)
            continue
        val=temp-n*(temp//n)
        print(val*(n-val))

        
        
        

                



