def cmp(a,b):
    return a[0]*b[1] - a[1]*b[0] >= 0

#solves from 0 to r excluded
def solve(tab, r):
    best_ind = r-1
    sum = tab[r-1] 
    lg = 1
    best_moy = (sum,lg)
    for i in range(r-2,-1,-1):
        sum += tab[i]
        lg += 1
        moy = (sum,lg)
        if cmp(moy,best_moy):
            best_ind = i
            best_moy = moy
    l = best_ind
    right_sum,lg = best_moy
    mini,maxi = 0,0
    if right_sum%lg == 0:
        mini,maxi = right_sum//lg,right_sum//lg
    else:
        mini = right_sum//lg
        maxi = mini + 1
    if l == 0:
        return mini,maxi
    else:
        m,M = solve(tab,l)
        return min(m,mini),max(M,maxi)

p = []    
t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    mini,maxi = solve(l,n)
    p.append(maxi-mini)
for x in p:
    print(x)
