import java.io.*;
import java.util.*;

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