import java.util.*;
import java.io.*;
public class customisingTrack {
    public static int minInconvinience(int[] arr) {
        int sum = 0;
        for (int ele : arr)
            sum += ele;
        int n = arr.length;
        int m = sum % n;
        int ans = m * (n - m);

        return ans;
    }

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t > 0) {  
            int n = Integer.parseInt(br.readLine());  
            String[] cars = br.readLine().split(" ");
            int[] arr = new int[n];
            for(int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(cars[i]);
            }

            System.out.println(minInconvinience(arr));

            t--;
        }
    }
}