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(1e9)+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)
    
        
    
        
    
                
    
    
    
            
            
            
        
                    
                
                    
                
                

                

        
                
                    
                
                
    
