#PROBLEM B1

def distributeSum(n,ls):
  sum = 0
  for i in ls: 
    sum += i
  if n != 0:
    left = sum%n
  else:
    left = 0
  result = (n-left)*left
  return result

def customTrack(): 
  ncases = int(input())
  for case in range(ncases):
    n = int(input())
    ls = list(map(int,input().split()))
    print(distributeSum(n,ls))

customTrack()