#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define pb push_back
#define mpp make_pair 
#define ff first 
#define ss second 
#define Sort(aa) sort(aa.begin(), aa.end())

void solve()
{
  int n, s=0, r, t;
  cin >> n;
  int arr[n];
  rep(i,0,n)
  {
    cin >> arr[i];
    s += arr[i];
  }
  r = s%n;     // 7
  t = n - r;  // 3
  cout << r*t << endl;
}

signed main()
{
  fst_io;

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  test() solve();
  return 0;
}
