#include <iostream>
using namespace std;
using ll = long long ;
int main() {
    int t; cin >> t;
    while(t--) {
        ll  n,q; cin >> n;
        ll sum = 0;
        for(int i = 0; i < n; i++) {cin >> q; sum += q;}
        cout << (sum % n) * (n - (sum % n)) << endl;
    }
    return 0;
}
