import java.util.Scanner;



public class Intern {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n=sc.nextInt();
            int []arr=new int[n];
            long c=0;
            for (int i = 0; i < n; i++) {
                arr[i]=sc.nextInt();
                c+=arr[i];
            }
           // System.out.println(c%n);
            if(c%n==0)
            {
                System.out.println("0");
            }
            else
            {
                System.out.println(c%n*(n-c%n));
            }

        }


    }
}

