/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Solution {
	public static void main(String[] args) throws java.lang.Exception {
		// your code goes here
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int k = Integer.parseInt(br.readLine());
		while (k-- > 0) {
			 int n=Integer.parseInt(br.readLine());
			String[] B = br.readLine().split(" ");
			int arr[]=new int[n];
			int sum=0;
			for(int i=0;i<n;i++)sum+=Integer.parseInt(B[i]);
			System.out.println((sum%n)*(n-(sum%n)));
		}

	}
}