import sys
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

m = inp()
for i in range(m):
    n = inp()
    arr = inlt()
    total = 0
    for i in range(n):
        total = total + arr[i]
    k = total % n
    print(k)
#     print(total)