import java.util.*;

public class abc {
    static long[] inArray(int n,Scanner sc){
       long a[]=new long[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextLong();
        }
        return a;
    }
    public static int gcd(int a, int b, int x, int y)
    {
        // Base Case
        if (a == 0)
        {
            x = 0;
            y = 1;
            return b;
        }

        int x1=1, y1=1; // To store results of recursive call
        int gcd = gcd(b%a, a, x1, y1);

        x = y1 - (b/a) * x1;
        y = x1;

        return gcd;
    }
    static int in(Scanner sc){
        return sc.nextInt();
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            long in[]=inArray(n,sc);
            long s=0;
            for (int i = 0; i <n ; i++) {
                s+=in[i];
            }
            System.out.println((s%n)*(n-s%n));

        }

    }
}
