#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gc getchar_unlocked
const int mod = 1000000007;

void solve()
{
    int n;
    cin >> n;
    vector<ll> traffic(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> traffic[i];
        sum += traffic[i];
    }
    ll x = sum % n;
    cout << x * (n - x) << endl;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}