#include <iostream>
#include<vector>
using namespace std;

int main(){
    vector<int> v;
    int q;
    cin>>q;
    unsigned long long int sum;
    unsigned long int a, n;
    while(q--){
        cin>>n;
        sum=0;
        for(unsigned int i=0;i<n;i++){
            cin>>a; sum=sum+a;
        }
        sum%=n;
        cout<<sum*(n-sum)<<endl;
    }
}
