import java.io.*;
public class B_Customising_the_Track {
    public static void main(String[] args) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   int t=Integer.parseInt(br.readLine());
   while(t>0){
    int n=Integer.parseInt(br.readLine());
   String s[]=br.readLine().split(" ");
   int ar[]=new int[n];
   int sum=0;
   
   for(int i=0;i<n;i++) {ar[i]=Integer.parseInt(s[i]); sum+=ar[i];}
   int u=sum%n;
   if(u==0) System.out.println("0");
   else System.out.println(u*(n-u));

   
t--;
   }


   }
}