import java.util.Scanner;

public class CustomisingtheTrack {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s= new Scanner(System.in);
		int t= s.nextInt();
		while(t-->0) {
			int n= s.nextInt();
			int sum =0;
			int a=0;
			for(int i=0;i<n;i++) {
				a= s.nextInt();
				sum+=a;
				sum=sum%n;
			}
			sum=sum%n;
			int zeroes=(int)(n-sum);
			int ones=(int)sum;
			double ans=zeroes*ones;
			System.out.println(ans);
			
		}
	}

}
