Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into $n$ sub-tracks. You are given an array $a$ where $a_i$ represents the number of traffic cars in the $i$-th sub-track. You define the inconvenience of the track as $\sum\limits_{i=1}^{n} \sum\limits_{j=i+1}^{n} \lvert a_i-a_j\rvert$, where $|x|$ is the absolute value of $x$.

You can perform the following operation any (possibly zero) number of times: choose a traffic car and move it from its current sub-track to any other sub-track.

Find the minimum inconvenience you can achieve.


-----Input-----

The first line of input contains a single integer $t$ ($1\leq t\leq 10000$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\leq n\leq 2\cdot 10^5$).

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0\leq a_i\leq 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.


-----Output-----

For each test case, print a single line containing a single integer: the minimum inconvenience you can achieve by applying the given operation any (possibly zero) number of times.


-----Examples-----

Input
3
3
1 2 3
4
0 1 1 0
10
8 3 6 11 5 2 1 7 10 4
Output
0
4
21


-----Note-----

For the first test case, you can move a car from the $3$-rd sub-track to the $1$-st sub-track to obtain $0$ inconvenience.

For the second test case, moving any car won't decrease the inconvenience of the track.

Source: codeforces | Difficulty: EASY
Tags: Combinatorics

Mathematics

Greedy algorithms


Solutions:
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	b = [s // n] * n
	ss = s % n
	print(ss * (n - ss))


import sys

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
m = inp()
for i in range(m):
	n = inp()
	arr = inlt()
	total = 0
	for i in range(n):
		total = total + arr[i]
	k = total % n
	print(k * (n - k))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if sum(arr) % n == 0 and sum(arr) >= n:
		print(0)
	else:
		s = sum(arr)
		rem = s % n
		res = (n - rem) * rem
		print(res)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		if sum(a) % n == 0:
			print(0)
			continue
		else:
			k = sum(a)
			s = 0
			b = [k // n + 1 for i in range(k % n)]
			b += [k // n for i in range(n - k % n)]
			b.sort()
			print((n - k % n) * (k % n))
main()


N = int(input())
for i in range(N):
	count = int(input())
	ms = list(map(int, input().split()))
	summa = sum(ms)
	b = summa % count * (count - summa % count)
	print(b)


import math
m = input()
for i in range(int(m)):
	track = int(input())
	cars = list(map(int, input().split()))
	total_cars = sum(cars)
	temp_track = track
	max_total = 1
	max_elm = 1
	for j in range(len(cars)):
		avg = total_cars / temp_track
		p = math.ceil(avg)
		cars[j] = p
		total_cars -= p
		temp_track -= 1
		if j == 0:
			max_elm = p
			max_total = 1
		elif p == max_elm:
			max_total += 1
		else:
			min_elm = p
	if max_total == track:
		min_elm = max_elm
		min_total = 0
	else:
		min_total = track - max_total
	print(abs(max_elm - min_elm) * max_total * min_total)


t = int(input())
for _ in range(t):
	input()
	a = list(map(int, input().split()))
	total = sum(a)
	tt = total // len(a)
	left = total % len(a)
	print((len(a) - left) * left)


import math
from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import random
import heapq

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	remain = sum(a) % n
	print(remain * (n - remain))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	m = s % n
	print(m * (n - m))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = sum(a) % n
	if r == 0:
		print(0)
		continue
	print(r * (n - r))


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	l = li()
	s = sum(l)
	base = s // n
	mod = s % n
	ans = mod * (n - mod)
	print(ans)
t = 1
t = ii()
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sm = sum(a)
	if sm < n:
		print((n - sm) * sm)
	elif sm % n == 0:
		print(0)
	else:
		t = sm % n
		print(t * (n - t))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	data = list(map(int, input().split()))
	total = sum(data)
	temp = total - total // n * n
	if temp == 0:
		print(0)
	else:
		print(temp * (n - temp))


def u():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	l = map(int, input().split())
	d = 0
	for el in l:
		d += el
		d %= n
	print((n - d) * d)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	a = s % n
	b = n - a
	print(a * b)


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split(' ')))
	sA = sum(A)
	g = sA % n
	l = n - g
	print(l * g)


from collections import Counter, deque
from sys import stdout
import time
from math import factorial, log, gcd

def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sum(a)
	o = s % n
	print(o * (n - o))
for t in range(int(input())):
	main()


a = int(input())
for i in range(a):
	b = int(input())
	c = [int(i) for i in input().split()]
	d = sum(c)
	e = d % b
	f = b - e
	print(e * f)


T = int(input())
for case in range(0, T):
	n = int(input())
	s = input().split()
	ans = 0
	for i in range(0, n):
		ans += int(s[i])
	t = ans % n
	print((n - t) * t)


def track(n, A):
	a = sum(A)
	b = (int(a / n) + 1) * n - a
	c = n - b
	return b * c
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	print(track(n, A))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	z = s % n * (n - s % n)
	print(z)


t = int(input())
for i in range(t):
	s = 0
	n = int(input())
	temp = list(map(int, input().split()))
	s = sum(temp)
	print(s % n * (n - s % n))


for _ in range(int(input())):
	n = int(input())
	a = sum(map(int, input().split())) % n
	print(a * (n - a))


import os
import sys
import math
import collections
import functools
import itertools
import heapq
import bisect
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcde'
MOD = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def INT():
	return int(input())

def STR():
	return input()

def INTs():
	return tuple(map(int, input().split()))

def ARRINT():
	return [int(i) for i in input().split()]

def ARRSTR():
	return [i for i in input().split()]
for _ in range(INT()):
	n = INT()
	arr = ARRINT()
	S = sum(arr)
	(a, b) = divmod(S, n)
	print(b * (n - b))


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	print(sum(p) % n * (n - sum(p) % n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	c2 = s % n
	c1 = n - c2
	print(c1 * c2)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sm = sum(a)
	a = sm % n
	b = n - a
	print(a * b)


for _ in range(0, int(input())):
	n = int(input())
	s = sum(map(int, input().split()))
	print(s % n * (-s % n))


def debug(*a):
	return
	print('[DEBUG]', *a)

def solve_case():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	a0 = s // n
	a1 = a0 + 1
	n1 = s % n
	n0 = n - n1
	debug(a0, a1)
	debug(n0, n1)
	print(n0 * n1)
n = int(input())
for i in range(n):
	solve_case()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		tot = sum(a)
		rest = tot - tot // n * n
		if tot % n == 0:
			print(0)
		else:
			print(rest * (n - rest))
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	(n, t) = (readint(), sum(readarri()))
	print((n - t % n) * (t % n))

def main():
	t = 1
	t = readint()
	for _ in range(t):
		solve()
main()


t = int(input())
for hh in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	su = sum(a)
	li = [0] * n
	val = su // n
	rem = su % n
	if rem == 0:
		print(0)
	else:
		print(rem * (n - rem))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		arr = get_list()
		summ = sum(arr)
		each = summ // n
		rem = summ - each * n
		get_print_int(rem * (n - rem))
solve()


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split(' ')))
	S = sum(A)
	print(S % N * (N - S % N))


num = int(input())
for i in range(num):
	n = int(input())
	arr = input().split(' ')
	arr = list(map(int, arr))
	s = sum(arr)
	avg = int(s / n)
	remain = s - avg * n
	print(remain * (n - remain))


import math

def readint():
	return int(input())

def intline():
	return [int(e) for e in input().split()]

def mod_add(a, b):
	return (a + b) % MOD

def mod_mul(a, b):
	return a * b % MOD

def mod_pow(a, b):
	if b == 0:
		return 1
	rt = mod_pow(a, b // 2)
	res = mod_mul(rt, rt)
	if b % 2:
		res = mod_mul(res, a)
	return res

def inverse(x):
	return mod_pow(x, MOD - 2)

def mod_div(a, b):
	return mod_mul(a, inverse(b))
_cases = True
t = 1
if _cases:
	t = int(input())

class Solver:

	def solve(tc):
		n = readint()
		a = intline()
		s = sum(a)
		avg = s // n
		extra = s - avg * n
		ans = extra * (n - extra)
		print(ans)
for tc in range(1, t + 1):
	Solver.solve(tc)


def pro(arr):
	n = len(arr)
	if n == 1:
		print(0)
		return
	k = sum(arr)
	rem = k % n
	print(rem * (n - rem))
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pro(arr)


from __future__ import print_function
from sys import stdin
from heapq import *
from math import log2, ceil, sqrt, gcd, log
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	a = gil()
	md = sum(a) % n
	print(md * (n - md))


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	x = sum(w) % n
	print(x * (n - x))


any = 1

def get():
	str = input()
	a = str.split()
	b = []
	for i in range(0, len(a)):
		b.append(int(a[i]))
	if len(b) == 1:
		return b[0]
	else:
		return b

def getarray():
	str = input()
	a = str.split()
	b = []
	for i in range(0, len(a)):
		b.append(int(a[i]))
	return b

def cout(a):
	for i in range(len(a) - 1):
		temp = str(a[i])
		print(temp, end=' ')
	print(str(a[len(a) - 1]))
c = get()
for i in range(c):
	n = get()
	a = getarray()
	sume = 0
	re = 0
	for x in a:
		sume = sume + x
	if sume % n == 0:
		print('0')
	else:
		re = sume % n
		print((n - re) * re)


def tracks(l, n):
	leftover = sum(l) % n
	return leftover * (n - leftover)
ans = []
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans.append(tracks(l, n))
for i in ans:
	print(i)


from __future__ import division, print_function
from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
import os, sys, math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())

def add_set():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
mod = 1000000007

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPower2(x):
	return x and (not x & x - 1)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	t = ii()
	for _ in range(t):
		n = ii()
		a = li()
		res = sum(a) // n
		rem = sum(a) - res * n
		print((n - rem) * rem)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
solve()


def calc():
	n = int(input())
	l = list(map(int, input().split(' ')))
	ss = sum(l)
	ans = ss % n * (n - ss % n)
	print(ans)
t = int(input())
for _i in range(t):
	calc()


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range
for t in r(IN()):
	n = IN()
	a = LI()
	sm = sum(a)
	tt = sm % n
	print(tt * (n - tt))


import math
import sys
from functools import reduce
import decimal
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	total = sum(arr)
	remaining = total % n
	print(remaining * (n - remaining))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = sum(l) % n
	print(d * (n - d))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	su = sum(l)
	print((n - su % n) * (su % n))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	temp = sum(vals)
	val = temp - n * (temp // n)
	print(val * (n - val))


n = int(input())
l1 = []
l2 = []
for i in range(n):
	l1.append(int(input()))
	l2.append([int(x) for x in input().split()])
for i in range(n):
	a = sum(l2[i])
	b = a % l1[i]
	if b == 0:
		print(0)
	else:
		print(b * (l1[i] - b))
print()


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	T = sum(arr)
	if T < n:
		print(T * (n - T))
	elif T % n == 0:
		print(0)
	else:
		quot = T // n
		diff = T - quot * n
		print((n - diff) * diff)


tt = int(input())
for x in range(tt):
	tot = int(input())
	sm = sum(list(map(int, input().split(' '))))
	b = sm % tot
	print((tot - b) * b)


for i in range(int(input())):
	n = int(input())
	m = sum(map(int, input().split())) % n
	print(m * (n - m))


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 16
md = 10 ** 9 + 7
for testcase in range(II()):
	n = II()
	aa = LI()
	s = sum(aa)
	r = s % n
	ans = r * (n - r)
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	ar = list(map(int, input().strip().split()))[:n]
	total = sum(ar)
	a = total // n
	b = total % n
	a = n - b
	ans = a * b
	print(ans)


import sys
import bisect

def get_line():
	return list(map(int, sys.stdin.readline().strip().split()))

def in1():
	return int(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')
for _ in range(in1()):
	n = in1()
	a = get_line()
	t1 = sum(a)
	if t1 % n == 0:
		print(0)
	else:
		t = t1 // n
		c = 0
		t2 = t1 % n
		print((n - t2) * t2)


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	x = sum(arr)
	y = n - x
	if x % n == 0:
		cnt = 0
	elif x < n:
		cnt = x * y
	else:
		a = x // n
		b = x - a * n
		cnt = (n - b) * b
	print(cnt)


import sys, os
from difflib import SequenceMatcher
from collections import Counter
from bisect import bisect_left as bl, bisect_right as br
from io import BytesIO, IOBase
from itertools import accumulate
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def memoize(f):

	class memodict(dict):

		def __getitem__(self, *key):
			return dict.__getitem__(self, key)

		def __missing__(self, key):
			ret = self[key] = f(*key)
			return ret
	return memodict().__getitem__
LCSubstr = lambda a, b: SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def extended_gcd(a, b):
	(s, old_s) = (0, 1)
	(r, old_r) = (b, a)
	while r:
		q = old_r // r
		(old_r, r) = (r, old_r - q * r)
		(old_s, s) = (s, old_s - q * s)
	return (old_r, old_s, (old_r - old_s * a) // b if b else 0)

def modinv(a, m):
	(g, x, _) = extended_gcd(a % m, m)
	return x % m if g == 1 else None

def make_nCr_mod(max_n=2 * 10 ** 5, mod=10 ** 9 + 7):
	max_n = min(max_n, mod - 1)
	(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

	def nCr_mod(n, r):
		res = 1
		while n or r:
			(a, b) = (n % mod, r % mod)
			if a < b:
				return 0
			res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
			n //= mod
			r //= mod
		return res
	return nCr_mod

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
			r = mid - 1
	return -1

def PrefixSum(arr):
	return list(accumulate(arr))

class inputs:

	def single(self):
		return int(input())

	def mul(self):
		return map(int, input().split())

	def list(self):
		return list(map(int, input().split()))
inp = inputs()

def main():
	for i in range(inp.single()):
		n = inp.single()
		a = inp.list()
		s = sum(a)
		s1 = s // n * n
		d = s - s1
		print(d * (n - d))
main()


import math
import sys

def scan():
	return list(map(int, sys.stdin.readline().strip().split()))

def solution():
	for _ in range(int(input())):
		n = int(input())
		a = scan()
		x = sum(a) % n
		p = sum(a) // n
		print(x * (n - x))
solution()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	r = sum(arr) % n
	print(r * (n - r))


from math import ceil
from sys import stdin, stdout

def main():
	input = stdin.readline
	print = stdout.write
	for _ in range(int(input())):
		N = int(input())
		Array = list(map(int, input().split()))
		Sum = sum(Array)
		print(str(Sum % N * (N - Sum % N)) + '\n')
main()


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += a[i]
	m = s % n
	print((n - m) * m)


import os
import math
import sys
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')

def func(n_track, arr):
	total_car = sum(arr)
	rem = total_car % n_track
	inconv = rem * (n_track - rem)
	return inconv

def main():
	n_cases = int(parse_input())
	for i in range(n_cases):
		n_track = int(parse_input())
		arr = [int(i) for i in parse_input().split()]
		print(func(n_track, arr))
main()


from collections import Counter, defaultdict, deque
import math
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7

def solve():
	n = int(input())
	arr = [int(_) for _ in input().split()]
	s = sum(arr)
	r = s % n
	print(r * (n - r))
tt = int(input())
for test in range(tt):
	solve()


t = int(input())
m = []
for i in range(t):
	s = 0
	n = int(input())
	a = list(map(int, input().split()))
	(b, av) = (sum(a) % n, sum(a) / n)
	(a[:b], a[b:]) = ([int(av)] * b, [int(av) + 1] * (n - b))
	for i in range(len(a)):
		if i < b:
			s += n - b
	m += [s]
for i in m:
	print(int(i))


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = sum(l)
	if ans % n == 0:
		print(0)
	else:
		m = ans % n
		print(m * (n - m))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
import string
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	a = li()
	b = sum(a) % n
	if b == 0:
		print(0)
	else:
		print(b * (n - b))


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	s = sum((int(x) for x in input().split()))
	r = s % n
	ans.append(str((n - r) * r))
print('\n'.join(ans))


import math, sys
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	total = sum(arr)
	c1 = total // n
	have = total - c1 * n
	if have:
		print(have * (n - have))
	else:
		print(0)

def main():
	ts = 1
	ts = int(input())
	for t in range(1, ts + 1):
		solve()

def input():
	return sys.stdin.readline().rstrip('\n').strip()

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

def flush():
	sys.stdout.flush()
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	rem = sum(arr) % n
	print(rem * (n - rem))


from math import gcd

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		x = sum(a) % n
		print(max(x, n - x) * min(x, n - x))
main()


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	arr = s.split(' ')
	res = 0
	for a in arr:
		res += int(a)
	rem = res % n
	print(rem * (n - rem))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	k = s % n
	print(k * abs(k - n))


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += a[i]
	r = s % n
	print(r * (n - r))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	above = round((sum(a) / len(a) - sum(a) // len(a)) * len(a))
	same = len(a) - above
	print(same * above)


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	given_nums = map(int, input().split())
	num_sum = sum(given_nums)
	remainder = num_sum % n
	avg = ceil(num_sum / n)
	decreased_count = avg * n - num_sum
	res = decreased_count * (n - decreased_count)
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	sume = 0
	for j in a:
		sume += j
	avg = sume // n
	total = avg * n
	extra = sume - total
	ans = extra * (n - extra)
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	rem = sum(arr) % n
	print(rem * (n - rem))


def process(A):
	n = len(A)
	S = sum(A)
	x = S % n
	return (n - x) * x
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	print(process(A))


q = int(input())
for i in range(q):
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	print(sum(l) % n * (n - sum(l) % n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	t = s // n
	l = s % n
	print(l * (n - l))


for t in range(int(input())):
	n = int(input())
	a = sum(map(int, input().split()))
	print(a % n * (n - a % n))


from math import floor, ceil
for _ in range(int(input())):
	n = int(input())
	lanes = list(map(int, input().split()))
	s = sum(lanes)
	avg = s / n
	if avg <= 1:
		print((n - s) * s)
		continue
	(l, h) = (floor(avg), ceil(avg))
	if h != l:
		y = (s - n * l) // (h - l)
	else:
		y = 0
	print((n - y) * y)


t = int(input())
for i in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	s = sum(mas)
	x = s % n
	print((n - x) * x)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		x = sum(a) % n
		print(x * (n - x))
main()


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	su = sum(li)
	print((n - su % n) * (su % n))


test = int(input())
for t in range(test):
	n = int(input())
	lst = list(map(int, input().split()))
	s = sum(lst)
	ans = s % n * (n - s % n)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = sum(a)
	s = s % n
	print(s * (n - s))


from sys import *
from math import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	tot = 0
	val = sum(arr) / n
	if int(val + 0.5) == ceil(val):
		val = ceil(val)
	else:
		val = int(val)
	for i in range(n):
		tot += arr[i] - val
	tot = abs(tot)
	print((n - tot) * tot)


import collections
t = int(input())
for i in range(0, t):
	n = int(input())
	cars = list(map(int, input().split()))
	cars = sorted(cars)
	while cars[n - 1] - cars[0] > 1:
		x = 0
		y = n - 1
		while x <= y:
			total = cars[x] + cars[y]
			cars[x] = total // 2
			cars[y] = total - cars[x]
			x += 1
			y -= 1
		cars = sorted(cars)
	carval = []
	for key in collections.Counter(cars).keys():
		carval.append(key)
	carnum = []
	for val in collections.Counter(cars).values():
		carnum.append(val)
	incon = 0
	for x in range(0, len(carval)):
		for y in range(x + 1, len(carval)):
			temp = (carval[x] - carval[y]) * (carnum[x] * carnum[y])
			if temp < 0:
				temp *= -1
			incon += temp
	print(incon)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	total = sum(l)
	avg = total / n
	avgr = total // n
	if avg == avgr:
		print(0)
	else:
		c = round((avg - avgr) * n)
		ans = c * (n - c)
		print(int(ans))


for q in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	p = sum(l1)
	p1 = p // n
	r = p % n
	print(r * (n - r))


def main():
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

	def ncr(n, r):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % mod
			den = den * (i + 1) % mod
		return num * pow(den, mod - 2, mod) % mod

	def solve(n, arr):
		rem = sum(arr) % n
		print((n - rem) * rem)
		pass
	t = int(input())
	ans = []
	for _ in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		ans.append(solve(n, arr))
import sys, threading
import bisect
import math
import itertools
from sys import stdout
import heapq
from queue import PriorityQueue
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


for _ in range(int(input())):
	n = int(input())
	s = sum(list(map(int, input().split())))
	x = s % n
	y = n - x
	print(x * y)


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		n = int(input())
		l = sum(list(map(int, input().split())))
		print((n - l % n) * (l % n))
main()


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	summ = sum(arr)
	a = floor(summ / n) * n
	rem = summ - a
	print((summ - a) * (n - rem))


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()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	s = sum(arr)
	dv = s // n
	ans = []
	rem = s % n
	cnt = 0
	cnt += rem * (n - rem)
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	arr = map(int, input().split())
	s = sum(arr)
	r = s % n
	print(r * (n - r))


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	avg = sum(a) // n
	if avg == 0:
		ones = sum(a)
		zeroes = n - sum(a)
		print(ones * zeroes)
	elif sum(a) % n == 0:
		print(0)
	else:
		remaining_ones_to_be_added = sum(a) - n * avg
		print(remaining_ones_to_be_added * abs(n - remaining_ones_to_be_added))


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	su = sum(a)
	if su % n == 0:
		print(0)
	else:
		tmp = su // n
		r = su - tmp * n
		print((n - r) * r)


tests = int(input())
for test in range(tests):
	len = int(input())
	a = input().split()
	sum = 0
	for i in a:
		sum += int(i)
	r = sum % len
	print(r * (len - r))


a = int(input())
for i in range(a):
	n = int(input())
	b = [int(i) for i in input().split()]
	sum1 = sum(b)
	avg = sum1 // n
	rem = sum1 - avg * n
	print(rem * (n - rem))


t = int(input())
for i in range(t):
	n = int(input())
	data = [int(x) for x in input().split()]
	my_sum = sum(data)
	rest = my_sum % n
	other_part = n - rest
	print(rest * other_part)


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def main():
	tests = read_one_int()
	for _ in range(tests):
		n = read_one_int()
		elements = read_list_of_ints()
		cur_sum = sum(elements)
		ones = cur_sum % n
		zeros = n - ones
		print(ones * zeros)
main()


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	x = sum(l) % n
	print(x * (n - x))
	t -= 1


for s in [*open(0)][2::2]:
	l = map(int, s.split())
	total = 0
	x = (*l,)
	sz_of_array = len(x)
	for c in x:
		total += c
	avg = total // sz_of_array
	rem = avg * sz_of_array
	t_rem = total - rem
	print((sz_of_array - t_rem) * t_rem)


def solve(n, a):
	t = sum(a)
	avg = t // n
	f = t - avg * n
	s = n - f
	return f * s
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n == 0:
		print(0)
	else:
		k = s % n
		print(abs(n - k) * k)


def incon(a):
	n = len(a)
	su = 0
	for i in range(n):
		for j in range(i + 1, n):
			su = su + abs(a[i] - a[j])
	return su
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if sum(a) % len(a) == 0:
		print(0)
	else:
		su = sum(a)
		k = su % n
		print(k * (n - k))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	if s <= n:
		print(s * (n - s))
	elif s % n == 0:
		print(0)
	else:
		print(s % n * (n - s % n))


DEB = False

def solve(tests):
	return [min_incon(a) for a in tests]

def min_incon(a):
	n = len(a)
	s = sum(a)
	return s % n * (n - s % n)

def print_sol(sol):
	[print(min_inc) for min_inc in sol]

def print_test(t, tests):
	print()
	print(t)
	[print(test) for test in tests]
	print()

def parse_input():
	t = int(input())
	tests = [list(map(int, input() and input().split())) for _ in range(t)]
	return (t, tests)

def main():
	(t, tests) = parse_input()
	if DEB:
		print_test(t, tests)
	print_sol(solve(tests))
main()


from itertools import combinations
from functools import lru_cache
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))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	su = sum(ar)
	on = su - su // n * n
	ze = n - on
	print(ze * on)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	n = takein()
	arr = takeiar()
	var = sum(arr) % n
	print((n - var) * var)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takein()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	total = sum(a)
	e = total % n
	one = n - e
	two = e
	print(one * two)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	q = sum(a)
	x = q // n
	b = q - n * x
	print(b * (n - b))


T = int(input())
for i in range(T):
	n = int(input())
	L = input().split()
	s = 0
	for j in range(n):
		s = s + int(L[j])
	print(s % n * (n - s % n))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	count = sum(a)
	d = count % n
	count1 = d * (n - d)
	print(count1)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l) // n
	left = sum(l) % n
	p = []
	for i in range(n):
		p.append(s)
	x = n - 1
	while left:
		p[x] += 1
		left -= 1
		x = x - 1
	ans = 0
	d = {}
	for i in p:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	if len(d) == 1:
		ans = 0
	else:
		ans = 1
		for i in d:
			ans = ans * d[i]
	print(ans)
for testis in range(int(input())):
	solve()


import sys
import math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	r = sum(l)
	v = math.ceil(r / len(l))
	y = len(l) * v
	x = y - r
	w = len(l) - x
	ans = w * x
	print(ans)
t = int(input())
while t != 0:
	solve()
	t -= 1


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


import math
n = int(input())
while n != 0:
	n -= 1
	t = int(input())
	a = list(map(int, input().split()))
	new = 0
	for i in range(len(a)):
		new += a[i]
	k = new % t
	ans = k * (t - k)
	print(ans)


b = int(input())
p = 0
for i in range(0, b):
	n = int(input())
	m = list(map(int, input().split()))
	p = sum(m) % n
	print(p * (n - p))


import math
t = int(input())
for i in range(t):
	n = int(input())
	c = sum(map(int, input().split())) % n
	print((n - c) * c)


for p in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	s = sum(m)
	a = s // n
	b = s - a * n
	print(b * (n - b))


t = int(input())
for T in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	s = sum(A)
	mean = s // n
	rem = s % n
	for i in range(n):
		if i < rem:
			A[i] = mean + 1
		else:
			A[i] = mean
	A.sort()
	cursum = 0
	curnums = 0
	ans = 0
	for i in range(n):
		cursum += A[i]
		curnums += 1
		ans += curnums * A[i] - cursum
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	b = sum(A)
	print(b % n * (n - b % n))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	extra = s - s // n * n
	print(extra * (n - extra))


t = int(input())
for no in range(t):
	n = int(input())
	a = [int(num) for num in input().split(' ', n - 1)]
	x = sum(a) % n
	print((n - x) * x)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	temp = sum(arr) % n
	print(temp * (n - temp))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		total = sum(a)
		r = total % n
		k = n - r
		res = n * (n - 1) // 2
		if r > 1:
			res -= r * (r - 1) // 2
		if k > 1:
			res -= k * (k - 1) // 2
		print(res)
while True:
	try:
		main()
	except:
		break


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	print(s % n * (n - s % n))


for i in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	summ = sum(ls)
	ex = summ % n
	print((n - ex) * ex)


def my_sum(a):
	result = 0
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			result += abs(a[i] - a[j])
	return result

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	assert len(a) == n
	remainder = sum(a) % len(a)
	return remainder * (len(a) - remainder)
t = int(input())
for i in range(t):
	print(solution())


for _ in range(int(input())):
	n = int(input())
	(a, res) = ([int(i) for i in input().split()], 0)
	total = sum(a)
	if total % n == 0:
		print(res)
	elif total < n:
		print(total * (n - total))
	else:
		v1 = total // n
		v2 = total - v1 * n
		print((n - v2) * v2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	al = sum(a) // n
	rem = sum(a) % n
	res = 0
	res = rem * (n - rem)
	print(res)


def cf_730B(numbers: list):
	n = len(numbers)
	total = sum(numbers)
	rem = total % n
	return rem * (n - rem)
for _ in range(int(input())):
	n = int(input())
	print(cf_730B(list(map(int, input().split()))))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	k = s // n
	rem = s - k * n
	print(rem * (n - rem))


for i in range(int(input())):
	n = int(input())
	q = list(map(int, input().split()))
	x = sum(q)
	if x % n == 0:
		print(0)
	else:
		print(x % n * (n - x % n))


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	avg = math.floor(s / n)
	inc = s - avg * n
	print(inc * (n - inc))


n = int(input())
for i in range(n):
	l = int(input())
	arr = [int(i) for i in input().split()]
	total = sum(arr)
	n = len(arr)
	net = total % n
	if net == 0:
		print(0)
	else:
		print(net * (n - net))


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s <= n:
		print(s * (n - s))
	else:
		print(s % n * (n - s % n))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sumx = sum(a)
	x = sumx // n
	m = 0
	if sumx % n == 0:
		for i in range(n):
			a[i] = x
	else:
		for i in range(n):
			a[i] = x
		m = sumx % n
	print(m * (n - m))


try:

	def solve():
		n = int(input())
		lst = list(map(int, input().split()))
		sum_ = sum(lst) % n
		ans = sum_ * (n - sum_)
		print(ans)
	test = int(input())
	count = 1
	while count <= test:
		solve()
		count += 1
except EOFError:
	print(' ')


for _ in [*open(0)][2::2]:
	arr = list(map(int, _.split()))
	k = sum(arr) % len(arr)
	print(k * (len(arr) - k))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	temp = sum(vals)
	if n == 1:
		print(0)
		continue
	val = temp - n * (temp // n)
	print(val * (n - val))


def somar(lst):
	soma = 0
	for x in lst:
		soma += x
	return soma
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	soma = somar(A)
	print(soma % n * (n - soma % n))


for tc in range(int(input())):
	n = int(input())
	listy = [int(_) for _ in input().split()]
	que = sum(listy) % n
	print((n - que) * que)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	res = sum(li) % len(li)
	print(res * (n - res))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	z = sum(l)
	x = z // n
	y = z % n
	print((n - y) * y)


import math
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	l.sort()
	c = 0
	s = sum(l)
	s = s % n
	z = n - s
	print(z * s)


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	n = I()
	l = list(In())
	total = sum(l)
	si = total // n
	bas = total % n
	print(bas * (n - bas))
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def prime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
	return prime_flag
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	extra = s % n
	x = n - extra
	y = extra
	print(x * y)
	t = t - 1


def solve():
	n = int(input())
	a = sum(map(int, input().split()))
	(a, b) = (a % n, n - a % n)
	print(a * b)
k = int(input())
for i in range(k):
	solve()


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	rem = s % n
	d = (n - rem) % n
	print(d * rem)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	res = sum(a) // n
	rem = sum(a) - res * n
	print((n - rem) * rem)


import math
t = int(input())
for i in range(t):
	siz = int(input())
	lst = list(map(int, input().split()))
	ss = sum(lst)
	rem = ss % siz
	print(rem * (siz - rem))


import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
for i in range(II()):
	n = II()
	a = L(I())
	s = sum(a)
	s %= n
	P(s * (n - s))


t = int(input())
for x in range(t):
	n = int(input())
	liczby = list(map(int, input().split()))
	suma = sum(liczby)
	reszta = suma % n
	srednia = suma // n
	if suma % n == 0:
		wynik = 0
	if suma < n:
		wynik = suma * (n - suma)
	else:
		wynik = (n - reszta) * reszta
	print(wynik)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	if sum(l) % n == 0:
		print(0)
	elif sum(l) < n:
		print(n)
	else:
		y = sum(l) // n
		ans = y * n
		diff = sum(l) - ans
		original = n - diff
		ans = original * diff
		print(ans)
		return
t = int(input())
while t != 0:
	solve()
	t -= 1


tests = int(input())
for _ in range(tests):
	n = int(input())
	t = list(map(int, input().split()))
	total = sum(t)
	if total < n:
		print((n - total) * total)
	else:
		res = total % n
		print((n - res) * res)


number_of_testcases = int(input())
for _ in range(number_of_testcases):
	n = int(input())
	arr = list(map(int, input().split()))
	sum1 = 0
	for i in range(n):
		sum1 = sum1 + arr[i]
	total_num = sum1 % n
	average = sum1 // n
	if sum1 != average * n:
		print(total_num * (n - total_num))
	else:
		print(0)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
from random import randint as ri
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	ele = sum(arr)
	cur = []
	mean = ele // n
	left = ele % n
	cur = [mean for i in range(n)]
	for i in range(left):
		cur[i] += 1
	ct1 = cur.count(mean)
	ct2 = cur.count(mean + 1)
	ans = ct1 * ct2
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	large = sum(a) % n
	small = n - large
	print(large * small)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	temp = sum(arr) // n
	rem = sum(arr) - temp * n
	print(rem * (n - rem))


import re
inputs = []
while True:
	try:
		line = input()
	except EOFError:
		break
	inputs.append(line)
n = inputs[0]
cn = 0
x = 0
a = 0
for i in range(1, int(n) + 1):
	cn = int(inputs[2 * i - 1])
	x = sum(map(int, re.findall('\\d+', inputs[2 * i])))
	a = x % cn
	print(a * (cn - a))


from math import *

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	k = sum(arr) % n
	ans = k * (n - k)
	print(ans)
n = int(input())
for _ in range(n):
	solve()


for run in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	s = sum(lst)
	print(s % n * (n - s % n))


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	s = sum(lst)
	k = s % n
	res = k * (n - k)
	print(res)


import sys
from math import ceil, floor, modf, sqrt
from collections import deque

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(get_ints())

def input():
	return sys.stdin.readline().strip()

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
T = int(input())
while T > 0:
	n = int(input())
	Arr = get_array()
	s = sum(Arr)
	each = s // n
	p = s % n
	left = n - p
	ans = p * left
	print(ans)
	T -= 1


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	s = sum(a)
	if s % n == 0:
		print(0)
	else:
		ans = s % n * (n - s % n)
		print(ans)


import sys

def solve(n, cars):
	s_cars = sum(cars)
	return s_cars % n * (n - s_cars % n)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		cars = list(map(int, input().split()))
		print(solve(n, cars))
	pass
sys.exit(main())


for k in range(int(input())):
	n = int(input())
	W = list(map(int, input().split()))
	Sum = sum(W)
	print((n - Sum % n) * (Sum % n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	h = sum(a)
	if h % n == 0:
		print(0)
	else:
		r = h % n
		print(r * (n - r))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s >= n:
		x = s % n
		print(x * (n - x))
	else:
		print((n - s) * s)


for s in [*open(0)][2::2]:
	n = len((a := s.split()))
	r = sum(map(int, a)) % n
	print(r * (n - r))


from collections import Counter
from sys import stdin, stderr
input = stdin.readline

def dbp(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def get_int_list():
	return [int(x) for x in input().strip().split()]

def slow_match(n, extras):
	count = 0
	for i in range(n):
		for j in range(i + 1, n):
			if i < extras and j >= extras:
				count += 1
	return count

def do_thing():
	n = int(input())
	alist = get_int_list()
	total = sum(alist)
	(flravg, extras) = divmod(sum(alist), len(alist))
	r = (n - extras) * extras
	return r

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def lcm(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr = szzz()
	s = sum(arr)
	rem = s % n
	print(rem * (n - rem))


import sys
sys.stderr = sys.stdout

def solve(n, A):
	i = sum(A) % n
	j = n - i
	return i * j

def case():
	n = readint()
	A = readintl()
	m = solve(n, A)
	return str(m)

def main():
	t = readint()
	print('\n'.join((case() for _ in range(t))))

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def lstr(l):
	return ' '.join(map(str, l))

def llstr(ll):
	return '\n'.join(map(lstr, ll))

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.__stderr__)
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	n = val()
	l = sum(li())
	temp = l % n
	ans = 0
	for i in range(temp):
		ans += n - temp
	print(ans)


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()))

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)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	suma = 0
	for x in a:
		suma += x
	diff = suma // n
	larger = suma - diff * n
	less = n - larger
	print(less * larger)


def FindSolution(n, arr):
	s = sum(arr)
	val = s % n
	return val * (n - val)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(FindSolution(n, arr))


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations, combinations_with_replacement, product
from collections import *
M = 10 ** 9 + 7
import heapq
from bisect import *
from functools import lru_cache
from queue import PriorityQueue
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

class Graph(object):

	def __init__(self, vertices):
		self.graph = defaultdict(list)
		self.V = vertices

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def connectedComponents(self):
		unvisited = set(range(self.V))
		queue = deque()
		count = 0
		while len(unvisited) > 0:
			count += 1
			v = next(iter(unvisited))
			unvisited.remove(v)
			queue.append(v)
			while len(queue) > 0:
				v = queue.popleft()
				for w in self.graph[v]:
					if w in unvisited:
						unvisited.remove(w)
						queue.append(w)
		return count

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def ngr(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def subset(arr, n, ans, c):
	if n == 0:
		print(c)
		ans.add(tuple(sorted(c)))
		return
	else:
		op = c + [arr[n - 1]]
		subset(arr, n - 1, ans, op)
		subset(arr, n - 1, ans, c)

def catalan(n):
	if n == 0 or n == 1:
		return 1
	catalan = [0] * (n + 1)
	catalan[0] = 1
	catalan[1] = 1
	for i in range(2, n + 1):
		for j in range(i):
			catalan[i] += catalan[j] * catalan[i - j - 1]
	return catalan[n]

def isP(p, i, j):
	if j <= i:
		return True
	if p[i] != p[j]:
		return False
	return isP(p, i + 1, j - 1)

def main():
	t = 1
	t = inpu()
	for _ in range(t):
		n = inpu()
		arr = lis()
		s = sum(arr)
		t = s % n
		print((n - t) * t)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	sum = 0
	for i in l:
		sum = sum + i
	k = sum % n
	print(k * (n - k))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	sum_n = sum(arr)
	av = sum_n // n
	rest = sum_n - av * n
	print((n - rest) * rest)


for _ in range(int(input())):
	l = int(input())
	nums = list(map(int, input().split()))
	s = sum(nums) % l
	print(s * (l - s))


import sys
for i in range(int(input())):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	S = sum(a)
	e = S % n
	print(e * (n - e))


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()
		r = sum(a) % n
		print(r * (n - r))
solve()


import os, sys, time, collections, math, pprint, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (1 << 60, 0, int(1000000000.0 + 7))
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)
ceil = lambda n, x: (n + x - 1) // x
(osi, oso) = ('/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
input = sys.stdin.readline

def maps():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(maps())
	s = sum(a)
	if s % n:
		avg = s // n
		left = (avg + (s - avg * n)) % n
		print((s - avg * n) * (n - (s - avg * n)))
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	n1 = sum(A) % n
	print((n - n1) * n1)