#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <cstring>
#include <bits/stdc++.h>

#define endl "\n"
#define sss(a) scanf("%d",&a)
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define int ll
#define ull unsigned long long
#define sd(a) scanf("%d",&a)
#define  sldd(a, b) scanf("%lld %lld", &a,&b)
#define  sld(a) scanf("%lld",&a)
#define pld(d) printf("%lld\n",d)
#define itn int
#define log(a, b) log(a)/log(b)
#define hh endl
#define ppp(a) printf("%lld\n",a)
#define cf cin >> t;while(t--){solve;}
#define pii pair<int,int>
#define sssc(a) scanf("%c",&a)
#define rep(i, a, b) for(int i=a;i<=b;i++)
#define per(i, a, b) for(int i=b;i>=a;i--)
#define mm(a, b) memset(a,b,sizeof(a))
#define debug cout << "debug" << endl;
using namespace std;

// 内联函数要先声明
inline int max(int a, int b);

inline int min(int a, int b);

int max(int a, int b) {
    return (a > b ? a : b);
}

int min(int a, int b) {
    return (a < b ? a : b);
}

//快速幂
int kuai(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) {
            ans = ans * a;
        }
        a = a * a;
        b = b / 2;
    }
    return ans;
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

/*
 * *********************************************************************************************************************
 */
int n;
int a, b;
const int maxn = 2e5 + 10;
int arr[maxn];

void slove() {
    cin >> n;
    int sum = 0;
    for (itn i = 1; i <= n; i++) {
        int x;
        cin >> x;
        sum += x;
    }
    int num = sum % n;
    int ans = num * (n - num);
    cout << ans << endl;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        slove();
    }
    return 0;
}