import java.io.*;
import java.util.*;
public class Codeforces10 {
    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());}

        String nextLine(){
            String str = "";
            try {
                str=br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    public static void main(String[] args)throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
        //t -> test cases;
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            int s[] = new int[n];
            int sum = 0;
            for(int i=0; i<n; i++){
               s[i] = sc.nextInt();
               sum+=s[i];
            }
            int mod = sum%n;
            int incon = mod*(n-mod);
            output.write(incon+"\n");
        }
        output.flush();
    }
}
