"""
author: Manoj
inp_start
3
3
1 2 3
4
0 1 1 0
10
8 3 6 11 5 2 1 7 10 4

inp_end
01011
30201


"""
tcs = int(input())
for tc in range(tcs):
	n = int(input())
	L = list(map(int, input().split()))
	t = sum(L)
	#if t<n:
	#	print(t*2)
	#else:
	c = t%n
	print((c*(n-c)))