/*package whatever //do not write package name here */

import java.io.*;

public class GFG {
	public static void main (String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
	    String[] str;
	    int i=0;
	    for(i=0;i<t;i++)
	    {
	        int n=Integer.parseInt(br.readLine());
	        if(n==1||n==2)
	        {
	            
	        }
	        str=br.readLine().split(" ");
	        long sum=0;
	        int j=0;
	        for(j=0;j<n;j++)
	        {
	            sum+=Integer.parseInt(str[j]);
	        }
	        long r=sum%n;
	        System.out.println(r*(n-r));
	    }
	}
}