import java.util.*;
public class HelloWorld{

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