import java.util.*;

public class track
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
 
		int t = scan.nextInt();
 
		for (int j=0;j<t ;j++ ) 
		{
			
			int n= scan.nextInt();
 
			long sum=0;
			for (int i=0;i<n ;i++ )
			{
				sum+= scan.nextLong();
			}
 
			long rem  = sum %n;
 
			System.out.println(rem*(n-rem));
		}
	}
}