import java.util.ArrayList;
import java.util.Collections;
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();
			Double sum =0d;
			for(int i=0;i<n;i++) {
				int a= s.nextInt();
				sum+=a;
			}
			int ones=(int)(sum%n);
			int zeroes=n-ones;
			System.out.println(zeroes*ones);
			
		}
	}

}
