#include <bits/stdc++.h>
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(0);
#define endl "\n"
#define pb push_back
#define D(x) cout << "#" << x << endl;
#define LL long long
#define HI cout << endl \
                << "hi" << endl;
using namespace std;

// SOLUTION ..........
LL gcd(LL x, LL y) { return y == 0 ? x : gcd(y, x % y); }
void solv()
{
    LL n;
    cin >> n;
    LL a[n], sum = 0, i;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    LL q = sum % n;
    cout << q * (n - q) << endl;
}

// MAIN FUNCTION ..........
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    fast
        LL test = 1;
    cin >> test;
    while (test--)
    {
        solv();
    }
    return 0;
}
