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

#define ll long long
#define FOR(i, j, k, in) for (int i=j; i<k; i+=in)
#define RFOR(i, j, k, in) for (int i=j; i>=k; i-=in)

#define F(i, n) FOR(i, 0, n, 1)
#define MP make_pair
#define PB push_back

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef queue<int> QI;
typedef stack<int> SI;

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    cin >> t;
    while(t--) {
        ll n;
        cin >> n;
        ll sum = 0;
        F(i, n){
            ll temp;
            cin >> temp;
            sum+=temp;
        }
        ll v = sum % n;
        ll ans = v * (n-v);
        cout << ans << endl;
    }
}
