import java.io.*;
import java.util.*;
public class p8  {
	public static void main(String[] args) throws IOException {
		Scanner sc= new Scanner(System.in);
		int t= sc.nextInt();
		for(int i=0;i<t;i++) {
			int n= sc.nextInt();
			int sum=0;
			int ans=0;
			for(int j=0;j<n;j++) {
				sum+=sc.nextInt();
				
			}
			int tmp= sum%n;
			ans=tmp*(n-tmp);
			
			System.out.println(ans);
		}

	}

}
