import java.util.*; 

import java.io.*; 

public class cs { 
    
     public static void main(String args[]) throws IOException { 
	  
	    BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); 
	    
		StringTokenizer st = new StringTokenizer("");  
		
		int t = Integer.parseInt(br.readLine()); 
		 
		while(t-- > 0 ){ 
		
		int n = Integer.parseInt(br.readLine()); 
		
		long a[]=new long[n]; 
		
	    st=new StringTokenizer(br.readLine());  
		 
		 long sum = 0;
		
	    for(int i = 0 ; i < n; i++) { 
		
		   a[i] = Long.parseLong(st.nextToken());  
		   
		   sum+=a[i];
		    
		  } 
		     
            long ans = sum%n; 
			
			long ans1 = n-sum%n; 
			 
			 System.out.println(ans*ans1);  
			 
		 
		}
		
		}
   }