import java.util.Scanner;

public class customizingTHeTracks {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Scanner sc=new Scanner(System.in);
		 int t=sc.nextInt();
		 while(t-->0) {
	       int n=sc.nextInt();
	      
	       int arr[]=new int[n];
	       int sum=0;
	       for(int i=0;i<n;i++) {
	    	   arr[i]= sc.nextInt();
	    	   sum=sum+arr[i];
	          }
	       int d= sum%n;
	       int c=d*(n-d);
	       System.out.println(c);

}
}}