//
// Created by Ray Ap on 2021/7/15.
//

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 5;
int a[MAXN];


void sol() {
    ll n, sum = 0;
    cin >> n;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int b = 0, k = 0;
    k = (n + sum) % n;
    cout << k * (n - k) << endl;

}

int main() {
    int N;
    cin >> N;
    while (N--) {
        sol();
    }
    return 0;
}