inp=int(input())
for k in range(inp):
    s=int(input())
    array=list(map(int,input().strip(' ').split(' ')))
    i=0
    sum1=0
    while i<s:
        d=0
        i=i
        while i<s and array[i]>0:
            d=max(array[i],d)
            i+=1
        sum1+=d
        if i<s:
            d=array[i]
        else:
            break
        while i<s and array[i]<0:
            d=max(array[i],d)
            i+=1
        sum1+=d
    print(sum1)


    
