t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    maxsum1 = -(10**10)
    maxlen = 0
    for j in range(n):
        fl = True
        if a[j]>0:
            prevsign = False
        else:
            prevsign = True
        length = 0
        summa = 0
        while(fl and j+length<n):
            if length+j < n:
                if not(prevsign) and (a[j+length]>0):
                    prevsign = True
                    summa += a[j+length]
                elif (prevsign) and (a[j+length]<0):
                    prevsign = False
                    summa += a[j+length]
                else:
                    fl = False
            else:
                fl = False
            length += 1
        length -=1 
        if length>=maxlen:
            maxlen = length
            if summa>maxsum1:
                maxsum1 = summa
    print(maxsum1)
