#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
      ll n;
      cin>>n;
      ll arr[n];
      for(int i=0;i<n;i++)
      {
          cin>>arr[i];
      }
      ll sum=0;
      for(int i=0;i<n;i++)
      {
          sum+=arr[i];
      }
      ll d= sum%n;
     cout<<(n-d)*d<<endl;
    }
}