#include<bits/stdc++.h>
using namespace std;
 
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define endl            "\n"
#define mp              make_pair
#define pb              push_back
#define ins             insert
#define lb              lower_bound
#define ub              upper_bound
#define ff              first
#define ss              second
#define sz(x)           (ll)(x).size()
#define vi              vector<int>
#define mt              make_tuple
#define mii             map<int,int>
#define um              unordered_map<int,int>
#define pii             pair<int,int>  
#define maxpq           priority_queue<int>
#define minpq           priority_queue<int,vi,greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define all(x)          x.begin(), x.end()
#define allr(x)         rbegin(x), rend(x)
#define w(x)            int x; cin>>x; while(x--)  
#define goog(tno)       cout << "Case #" << tno <<": "
#define trace(x)        cerr<<#x<<": "<<x<<" "<<endl;
 
typedef long double ld;
#define ll  long long int
#define ull unsigned ll
const int MOD = 1000000007;
const ll INF = 1e18;
const ld pi =3.14159265359; 
// const int mod = 1000003;
 
template <class T> ll maxpower(T a , T b){ll ans = 0;while(a > 0 && a % b == 0){ans++;a /= b;}return ans;}
template <class T> T mceil(T a, T b){if(a % b == 0) return a/b; else return a/b + 1;}
 
//---------------------------------------------------------------------------
// cin>> vector<T>
template <class T> istream &operator>>(istream &in, vector<T> &a){for (auto &i : a)cin >> i;return in;}
// cout << vector<T>
template <class T> ostream &operator<<(ostream &ostream, const vector<T> &c){for (auto &it : c) cout << it << " ";return ostream;}
//---------------------------------------------------------------------------
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main(){
    FIO;
    w(t){
        ll n;
        cin>>n;

        ll sum = 0;

        for(ll i=0;i<n;i++){
            ll x;
            cin>>x;

            sum += x;
        }

        cout<<sum%n*(n-sum%n)<<endl;
    }
}
 