#include<bits/stdc++.h>
using namespace std;
#define in long long

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("ip.txt","r",stdin);
freopen("op.txt","w",stdout);
#endif

in n;
cin>>n;
in c,b,s,q;

while(n--){
    cin>>c;
    in C=c;
    s=0;
    while(C--){
        in x;
        cin>>x;
        s+=x;
    }
    if(s%c==0)  cout<<0<<endl;
    else{
    q=s%c;
    b=c-q;
    cout<<q*b<<endl;
    }
}

return 0;
}