
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));	 
		StringTokenizer st
		= new StringTokenizer(br.readLine());
		int i,n,t,p;
		long k,j,l,m;
		t = Integer.parseInt(st.nextToken());
		for(p=1;p<=t;p++)
		{   
			st = new StringTokenizer(br.readLine());
		    n = Integer.parseInt(st.nextToken());
		    long a[] = new long[n];
		    k = 0;
		    st = new StringTokenizer(br.readLine());
		    for(i=0;i<n;i++)
	        {
		    	a[i]=Long.parseLong(st.nextToken());
	            k+=a[i];
	        }
		    l = k%n;
		    if(l==0)
		    {
		    	System.out.println(0);
		     continue;
		    }
		    	       
		 System.out.println(((l)*(n-l)));
	}	
	}
}
