from itertools import combinations
from functools import lru_cache
# @lru_cache(None)
import heapq
from collections import defaultdict
import re
import sys
import math
input=sys.stdin.readline     
t=int(input())
for i1 in range(1,t+1):
  n=int(input())
  l=list(map(int,input().split()))
  if sum(l)%n==0:
    print("0")
  else:
    p=sum(l)%n
    print(p*(n-p))  