import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class Main
{
	
    static final int mod = (int)1e9+7;
    public static void main(String[] args) throws Exception
    {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int test =in.nextInt();
        

        while(test-- > 0)      //test
        {  
        	int n=in.nextInt();
        	long a[]=new long[n];
        			long s=0;
        	for(int i=0;i<n;i++)
        	
        		{
        			a[i]=in.nextLong();s+=a[i];
        		}
        	
        	out.println( (n-(s%n))*(s%n) );
        	
        	
        }   //test
        out.flush();
        
    }
   
    
    
    
    public static void rotate(int arr[],int start, int end)
   	{
   	    int t=arr[end];
   	    for(int i=end-1;i>=start;i--)
   	        arr[i+1]=arr[i];
   	        arr[start]=t;
   	}
    
    static int[] intAr(int n)throws IOException
    {
    	FastReader in = new FastReader();
    	int a[]=new int[n];
        for(int i=0;i<n;i++)
        	a[i]=in.nextInt();
    		return a;
    		
    }
    static Long[] longAr(int n)throws IOException
    {
    	FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
    	Long a[]=new Long[n];
        for(int i=0;i<n;i++)
        	a[i]=in.nextLong();
    		return a;
    		
    }
    
    public static void reverse(int[] array)           //reverse array
    {
  
        // Length of the array
        int n = array.length;
  
        // Swaping the first half elements with last half
        // elements
        for (int i = 0; i < n / 2; i++) {
  
            // Storing the first half elements temporarily
            int temp = array[i];
  
            // Assigning the first half to the last half
            array[i] = array[n - i - 1];
  
            // Assigning the last half to the first half
            array[n - i - 1] = temp;
        }
    }
    
    static int getMin(int arr[], int n)                             //min element of array 
    {
        return Arrays.stream(arr).min().getAsInt();
    }
 
    static int getMax(int arr[], int n)                               //max element of array 
    {
        return Arrays.stream(arr).max().getAsInt();
    }
   
    static boolean isPrime(int n)                       // check number if prime int
    { 
        // Corner case 
       
        // Check from 2 to n-1 
        for (int i = 2; i <= Math.sqrt(n); i++) 
            if (n % i == 0) 
                return false; 
  
        return true; 
    } 															
    
    static boolean isPrime(long n)                              // check number if prime long
    { 
        
        for (int i = 2; i <= Math.sqrt(n); i++) 
            if (n % i == 0) 
                return false; 
  
        return true; 
    } 															
    
    
    static long gcd(long a, long b)                          // Recursive method to return gcd of a and b

    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
     
  
    static long lcm(long a, long b)                               // method to return LCM of two numbers
    {
        return (a / gcd(a, b)) * b;
    }
     
    static boolean isPalindrome(String str)                 //check if string is palindrome
    {
 
        
        int i = 0, j = str.length() - 1;
 
       
        while (i < j) {
 
            
            if (str.charAt(i) != str.charAt(j))
                return false;
 
          
            i++;
            j--;
        }
 
        // Given string is a palindrome
        return true;
    }
    
    
    static int countDigit(long n)           //No. of digits in a number
    {
        int count = 0;
        while (n != 0) {
            n = n / 10;
            ++count;
        }
        return count;
    }
    
    static long numDivisors(long b)             //No. of Divisors in long
    {
    	long ans=0;
    
		for(long i=1;i*i<=b;i++){
			if(b%i==0){
				ans++;
				if(i*i!=b)	ans++;
			}
		}
		return ans;
    }
    
    
    static int numDivisors(int b)             //No. of Divisors in int
    {
    	int ans=0;
		for(long i=1;i*i<=b;i++){
			if(b%i==0){
				ans++;
				if(i*i!=b)	ans++;
			}
		}
		return ans;
    }
    
    static int countOdd(int a[])
    {
    	int n=a.length;
    	int ans=0,i;
    	for(i=0;i<n;i++)
    	{
    		if(a[i]%2==1)
    			ans++;
    	}
    	return ans;
    }
  
    static int maxSubarraySum(int arr[], int n)        //kandane
    {
        int sum=0;
     int max=arr[0];
     for(int i=0;i<n;i++)
     {
         sum+=arr[i];
         if(sum>max)
         max=sum;
         if(sum<0)
         sum=0;
     }
     return max;
     // Your code here
     
    }
    
    
    
    
    
}



class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() throws IOException
    {
        if(st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }

        return st.nextToken();
    }

    public boolean hasNext() throws IOException
    {
        if(st != null && st.hasMoreElements())
        {
            return true;
        }

        String s = br.readLine();
        if(s == null) {
            return false;
        }

        st = new StringTokenizer(s);

        return st.hasMoreElements();
    }

    public int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    public String nextLine() throws IOException
    {
        return br.readLine();
    }
}