import sys;import math;from collections import deque;from bisect import bisect_left,bisect_right;I=sys.stdin.readline;II=lambda :int(I());IN=lambda x:map(int,x.split());L=lambda x:list(IN(x));M=1000000007;P=print;T=True;F=False
for i in range(II()):
	n=II()
	a=L(I())
	s=sum(a)
	s%=n
	P(s*(n-s))