from collections import deque, Counter
from collections import defaultdict as dfd
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop


MOD = 10**9 + 7
inf = float("inf")
ans_ = []

def nin():return int(input())
def ninf():return int(file.readline())

def st():return (input().strip())
def stf():return (file.readline().strip())

def read(): return list(map(int, input().strip().split()))
def readf():return list(map(int, file.readline().strip().split()))

# file = open("input.txt", "r")
def solve():
    for _ in range(nin()):
        n = nin(); arr = read()
        s = sum(arr)
        ex = s%n
        ans_.append(ex * (n-ex))
        
    
    
        
solve()

for i in ans_:
    print(i)
    