#include <iostream>

using namespace std;

int main() {

	int t;
	uint64_t n;
	uint64_t s;

	cin >> t;

	while (t--) {
		s = 0;

		cin >> n;

		for (int i = 0, temp = 0; i < n; i++) {
			cin >> temp;
			s += temp;
		}

		if (n == 1) {
			cout << 0 << '\n';
		} else {
			cout << (uint64_t)((s % n) * (n - (s % n))) << '\n';
		}
	}

	return 0;
}