#include <bits/stdc++.h>
using namespace std;

// ascii value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space

#define endl "\n"
#define int long long

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

// use error(args..)

const int INF = (int)2e9  + 10;
const int32_t MOD=1e9+7;
const int32_t MM=998244353;
const int N=200200;


void solve()
{

    int n;
    cin>>n;

    vector <int> v(n);

    int sum  =0;

    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sum += v[i];
    }

    //int foreach = sum/n;

    int ans = n - sum%n;

    int res = sum%n;
    res *= ans;
    cout<<res<<endl;

}

signed main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("newop.txt", "w", stdout);
    #endif

    int t = 1;

    cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}