#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ios ios_base::sync_with_stdio(false), cin.tie(NULL)
#define pb push_back
#define po pop_back()
#define umap unordered_map
#define uset unordered_set
#define mod 1000000007
#define pi 3.141592653589793238
#define maxe *max_element
#define mine *min_element
#define f(i,n) for(int i=0; i<n; i++)
#define f1(i,k,n) for(int i=k; i<n; i++)
#define p0(x) cout << x << " "
#define p1(x) cout << x << "\n"
#define p2(x, y) cout << x << " " << y << "\n"
#define p3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define ip pair<int,int>
#define pll pair<ll, ll>
#define mem(x,y) memset(x, y, sizeof(x))

ll power(ll a, ll b, ll p){
    a %= p;
    ll res = 1;
    while(b > 0){
        if(b&1){        // if b is odd
             res = (res*a)%p;
        }
        a = (a*a)%p;
        b = b >> 1;
    }
    return res;
}

ll gcd(ll a, ll b){

   return b? gcd(b, a%b): a;        

}

void solve(){
      ll n;
      cin >> n;
      ll arr[n];
      ll sum = 0;
      f(i,n){
          cin >> arr[i];
          sum += arr[i];
      }
      

      ll rem = sum%n;
      ll rem1 = n-rem;

      ll ans = rem*rem1;
      p1(ans);
  
}

int main(){
    ios;
    int t;
    cin >> t;
    while(t--){
       solve();
    }
    return 0;
}
