from __future__ import division,print_function
from heapq import*
import sys
le = sys.__stdin__.read().split("\n")[::-1]
af=[]
for zorg in range(int(le.pop())):
    n=int(le.pop())
    s= sum(list(map(int,le.pop().split())))
    r=s%n
    af.append(r*(n-r))
print("\n".join(map(str,af)))
