# https://codeforces.com/contest/1543/problem/B
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    rem = sum(arr) % n
    print(rem * (n-rem))
