import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class B {
    static HashMap<Long, Long> combos = new HashMap<>();
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintStream out = System.out;

        int t = Integer.parseInt(br.readLine());

        for (int i = 0; i < t; i++) {
            int n = Integer.parseInt(br.readLine());
            String[] in = br.readLine().split(" ");
            int sum = 0;
            for (String x : in) {
                sum = (sum + Integer.parseInt(x))%n;
            }
            out.println(sum*(n-sum));
        }

        System.out.flush();
    }
}