#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
int mod=1000000007;
using namespace std;
#define FOR3(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,a) for (int i=0;i<a;i++)
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bo4und
#define mp make_pair
#define fi first
#define se second
#define mii map<int,int>
#include<string>
using namespace std;
ll t,n;
int main()
{
    FAST;
   cin>>t;
   while(t--)
   {
     cin>>n;
     ll sum=0;
     for(int i=0;i<n;i++)
     {
         int x;
         cin>>x;
         sum+=x;
     }
     sum%=n;
     cout<<sum*(n-sum)<<'\n';
   }
}
