from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys

import copy

 
inf_var = 0
if inf_var == 1:
    inf = open('input.txt', 'r')
else:
    inf = sys.stdin
 
input = inf.readline
# sys.stdout = open('output.txt', 'w')
 
def read_one_int():
    return int(input().rstrip('\n'))


def read_one_float():
    return float(input().rstrip('\n'))
 
 
def read_list_of_ints():
    res = [int(val) for val in (input().rstrip('\n')).split(' ')]
    return res
 
def read_str():
    return input().rstrip()


def main():
    tests = read_one_int()

    for _ in range(tests):
        n = read_one_int()
        elements = read_list_of_ints()

        cur_sum = sum(elements)

        ones = cur_sum % n
        zeros = n - ones

        print(ones * zeros)



if __name__== '__main__':
    main()
