import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.abs;
/* https://codeforces.com/contest/1543/problem/B*/
public class b1543B{
    static FastScanner fs = new FastScanner();
    static PrintWriter fop = new PrintWriter(System.out);
     static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) {
        try {
            solve();
        } catch (Exception e) {
            return;
        }
    }

    
    static void solve() throws IOException{
       
        int T = fs.nextInt();
        while (T-- > 0) {
            int n=fs.nextInt(),a[] = fs.readArray(n),sum=0;
            for (int i : a) {
                sum+=i;
            }
            fop.println((sum%n)*(n-(sum%n)));
        }
        fop.flush();
        fop.close();
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

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