#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()

int main(){
    int tc;
    cin >> tc;
    while(tc--){
        int n;
        cin >> n;
        vector<int> vec(n);
        for(auto &x : vec) cin >> x;
        ll sum = accumulate(all(vec), 0ll);
        ll rem = sum % n;
        cout << rem * (n - rem) << '\n';
    }
}