
import java.util.Scanner;

public class CustomisingTrack {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t-->0){
            int n=sc.nextInt();
            int sum=0;
            for (int i = 0; i <n ; i++) {
                sum+=sc.nextInt();
            }
            int k=sum%n;
            System.out.println(k*(n-k));
        }
    }
}
