
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int search(int arr[],int target,int l,int r)
{
    int mid;
    while(r>l)
    {
        
        mid=(l+r+1)/2;
       
        if(target>=arr[mid])
            l=mid;
        else
            r=mid-1;
    }
    return r;
}
public static void main(String[] args)
{
   FastReader in = new FastReader();
   int t=in.nextInt();
   
   while(t-->0)
   {
       int sum=0,div;
       int n=in.nextInt();
       int arr[]=new int[n];
       
       for(int i=0;i<n;i++)
           arr[i]=in.nextInt();
       
       for(int i=0;i<n;i++)
           sum+=arr[i];
       
       div=sum%n;
       
       int ans=(n-div)*div;
       
       System.out.println(ans);
   }
}
}