import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class CustomisingtheTrack {
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(br.readLine());
            String s[] = br.readLine().split(" ");
            long a[] = new long[n];
            long sum = 0;
            for(int i = 0; i < n; i++) {
                a[i] = Long.parseLong(s[i]);
                sum += a[i];
            }
            long adds = sum % n;
            long ans = (adds) * (n - adds);
            System.out.println(ans);
        }
    }
}