
def FindSolution(n, arr):
    s = sum(arr)
    val = s % n
    return val * (n - val)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = [int(x) for x in input().split()]
    print(FindSolution(n, arr))