#include <iostream>

int main(void) {
	int count;
	std::cin >> count;
	for (int i = 0; i < count; ++i) {
		int number;
		std::cin >> number;
		int64_t sum = 0;
		for (int j = 0; j < number; ++j) {
			int part;
			std::cin >> part;
			sum += part;
		}
		std::cout << (sum % number) * (number - sum % number) << "\n";
	}
	return 0;
}
