for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    m = sum(l)//n
    if m!=0 and sum(l)%m == 0:
        print(0)
    else:
        extra = sum(l)-m*n
        print(extra*(n-extra))
