import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class CustomizingTheTrack {

	public static void main(String[] args) throws IOException {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));//new FileReader("cowdance.in")
		 PrintWriter out = new PrintWriter(System.out);//new FileWriter("cowdance.out")
		 StringTokenizer st = new StringTokenizer(read.readLine());
		 int t = Integer.parseInt(st.nextToken());
		 
		 for (int ie = 0; ie < t; ie++) {
		 st = new StringTokenizer(read.readLine());
		 int n = Integer.parseInt(st.nextToken());
		 st = new StringTokenizer(read.readLine());
		 long [] a = new long [n];
		 long sum = 0;
		 for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(st.nextToken());
			sum += a[i];
		 }
		  sum = (long) Math.ceil((double)sum/n);
		  Arrays.sort(a);
		 
		 while (a[n-1] > sum) {
			 long cur = a[n-1];
			 a[n-1] = sum;
			 long sub = cur-sum;
			 
			 for (int i = 0; sub > 0 && i < n-1; i++) {
				 if (a[i] + sub >= sum) {
					 a[i] += sum-a[i];
					 sub -= sum - a[i];
					 
				 }else {
					 a[i] += sub;
					 sub = 0;
				 }
				 
			 }
			 Arrays.sort(a);
			
		 }
		
		HashMap<Long, Long> dups = new HashMap<Long, Long>();
		ArrayList<Long> idx = new ArrayList<Long>();
		 for (int i = 0; i < n; i++) {
			 if (!dups.containsKey(a[i])) {
				 dups.put(a[i], (long) 1);
				 idx.add(a[i]);
			 }else {
				 dups.replace(a[i], dups.get(a[i]), dups.get(a[i])+1);
			 }
		 }
		 long ans = 1;
		 if (dups.size() == 1) {
			 ans = 0;
			 }else {
		 for (int i = 0; i < dups.size(); i++) {
			 ans *= dups.get(idx.get(i));
		 }
			 }
		 
		 out.println(ans);
		 
		 }
		 
		 
		 out.close();
	}

}
