T=int(input())
i=0
while i<T:
    n=int(input())
    if n==1:
        print(input())
    else:
        sum=0
        a=input().split()
        a=[int(x) for x in a]
        a=a+[-a[n-1]]
        if a[0]>0:
            s=1
        else:
            s=-1
        max=a[0]
        for t in a[1:]:
            if s*t>0 and t>max:
                max=t
            elif s*t<0:
                sum+=max
                max=t
                s=-s
        print(sum)                
            
    i+=1

    
