#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 14 11:45:43 2021

@author: aryansinha
"""

t=int(input())
for no in range(t):
    n=int(input())
    a=[int(num) for num in input().split(" ",n-1)]
    x=sum(a)%n
    print((n-x)*x)