
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {

        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();

            int[] A = new int[n];
            int sum = 0;
            for(int i = 0 ; i < n; i++) {
                A[i] = sc.nextInt();
                sum += A[i];
            }

            int div = sum / n ;
            int remainder = sum % n;

            out.println( (remainder) * (n - remainder));

        }

        out.flush();
        out.close();
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){ return Double.parseDouble(next()); }
    }

    void shuffleArray(long[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}
