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

public class P07 {
	static class FastReader{
		BufferedReader br ;
		StringTokenizer st;
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			
		}
		String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return  Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		float nextFloat() {
			return Float.parseFloat(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}catch(IOException e) {
				e.printStackTrace();
			}
			return str ;
		}
	}
	
 	public static  void main(String[] args)throws IOException {
		FastReader fs = new FastReader();
		int t = fs.nextInt();
		while(t-->0) {
			long n = fs.nextLong(),s = 0;
			for(int i =0;i<n;i++)s+=fs.nextInt();
			long k = s%n;
			System.out.println(k*(n-k));
		}
		
    }
	private static int gcd(int i, int j) {
		if(j==0) {
			return i;
		}
		return gcd(j,i%j);
	}
	
}
