#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define oo (int)(1e17)

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n + 1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            sum += a[i];
        }
        int rem = (sum % n);
        cout << (n - rem)*(rem) << endl;
    }
}
