import java.util.*;
import java.lang.String;
 import java.util.Arrays;
 import java.lang.Math;
 
public class Main {
 
  
       
    public static void main(String[] args) {
 
        Scanner in = new Scanner(System.in);
        int i,j,k,l,m,n,o,p,t=0;
        t=in.nextInt();
        
        for(i=0;i<t;i++)
        {
             n=in.nextInt();
             int a[]=new int[n];
             int s1=0;
             for(j=0;j<n;j++)
             {a[j]=in.nextInt();
                 s1=s1+a[j];
                }
                o=s1%n;
                p=o*(n-o);
                System.out.println(p);
             
        }
        
}
       
}