/*package whatever //do not write package name here */

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

public class GFG {
    //So much fucking easy am I dum dum :C
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int  t= sc.nextInt();
		while(t!=0){
		    t--;
		    int n = sc.nextInt();
		    int sum=0;
		    for(int i=0;i<n;i++){
		        sum+=sc.nextInt();
		    }
		    int x = sum%n;
		    System.out.println(x*(n-x));
		}
	}
}