#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;

        long long total_sum = 0;

        for(int i=0; i<n; i++){
            int temp;
            cin>>temp;
            total_sum += temp;
        }

        long long rem = total_sum%n;
        
        if(rem == 0) cout<<0<<endl;
        else cout<<(n - rem)*(rem)<<endl;
    }
    return 0;
}