#include<bits/stdc++.h>

using namespace std;

#define ll long long

void solve(){
    ll n;
    cin >> n;
    
    ll sum = 0;
    for(int i=0; i<n; i++){
        ll a;
        cin >> a;
        sum += a;
    }
    
    ll extra = sum % n;
    
    ll totalInconvinience = (n-extra) * extra;
    cout << totalInconvinience << endl;
}


int main(){
    int t;
    cin >> t;

    while(t--){
        solve();
    }
}
