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

public class CP {
    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 (Exception 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 (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }


    public static void main(String[] args) throws Exception {
        FastReader fs = new FastReader();
//        StringBuilder sb=new StringBuilder();
        PrintWriter out = new PrintWriter(System.out);
        int test = fs.nextInt();
        while (test-- != 0) {
            int n = fs.nextInt();
            String s = fs.nextLine().trim();
            String[] sa = s.split(" ");
            int sum = 0;
            for(String str : sa)
                sum += Integer.parseInt(str);
            int rem = sum % n;
            out.println(rem * (n - rem));    
        }
        out.close();

    }
}