/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
typedef long long int ll;
using namespace std;

int main()
{
    int t;cin>>t;
    while(t--){
       ll n,sum=0; cin>>n;
       
       for(int i=0;i<n;i++){
           int a;
           cin>>a;
           sum+=a;
       }
       ll p=sum%n;
       cout<<p*(n-p)<<endl;
    }
    return 0;
}
