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

#define int long long

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //-------------------------------
    #ifndef ONLINE_JUDGE//-----------
    freopen("input.txt","r",stdin);//
    freopen("output.txt","w",stdout);
    #endif
    //-------------------------

int t;cin >> t;
while(t--){
    int n,sum=0;cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
        sum+=v[i];
    }
    
    int f_ans = (sum%n)*(n-(sum%n));
    cout << f_ans << "\n";
}


    
}