from sys import stdin
from itertools import repeat
def solve():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, n))
    s = sum(a)
    r = s % n
    print r * (n - r)

T = int(stdin.readline())
for _ in xrange(T):
    solve()
