def solve():
    n = int(input())
    l = list(map(int, input().split()))

    s = sum(l)//n
    # print(sum(l))
    left = sum(l)%n
    p = []
    for i in range(n):
        p.append(s)
    x = n-1
    while left:
        p[x] +=1
        left -=1
        x = x  -1

    # print(p)
    ans = 0
    d = {}
    for i in p:
        if i in d:
            d[i]+=1
        else:
            d[i] = 1
    if len(d)==1:
        ans = 0
    else:
        ans = 1
        for i in d:
            ans = ans * d[i]
    print(ans)

for testis in range (int(input())):
    solve()