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


public class thisContestp2 {
	public static void main(String[] args) throws IOException {
		//BufferedReader br = new BufferedReader(new FileReader(new File("input.txt")));
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    // read line
	    int t = Integer.parseInt(br.readLine());
	    for(int i = 0; i < t; i++) {
		    int n = Integer.parseInt(br.readLine());
		    StringTokenizer st = new StringTokenizer(br.readLine());
		    int tot = 0;
		    for(int j = 0; j < n; j++) {
		    	tot += Integer.parseInt(st.nextToken());
		    	tot = tot % n;
		    }
		    System.out.println(tot * (n-tot));
	    }
		
		br.close();
	}
}
