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

int nc2(int n){
    if(n < 2){
        return 0;
    }
    return (n)*(n-1)/2;
}


signed main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  


    //code here

    ll t;
    cin >> t;
    while(t-->0){
        ll n;
        cin >> n;
        ll arr[n];
        ll sum = 0;
        for(ll i = 0; i < n; i++){
            cin >> arr[i];
            sum += arr[i];
        }
        ll x = sum % n;
        cout << x*(n-x) << endl;
    }   


    //end
    return 0;

}
