#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

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

int main() {
    int T;
    cin >> T;
    while(T --)
    {
        LL sum = 0;
        int n;
        cin >> n;
        for(int i = 0; i < n; ++ i)
        {
            int tp;
            cin >> tp;
            sum += tp;
        }
        sum = sum%n;
        LL cnt0 = n-sum, cnt1 = sum;
        LL ans = cnt0*cnt1;
        printf("%lld\n", ans);
    }
    return 0;
}
