
def alt(l,n):

    u=l[-1]
    p=0
    for k in range(n-1,-1,-1):

        if u < 0 and l[k]<0:
            u= max(u,l[k])
        elif u>0 and l[k]>0:
            u = max(u,l[k])
        else:
            p+=u
            u=l[k]

    p+=u
    return p
                
            
    







    
for k in range(int(input())):
    n = int(input())

    t = list(map(int,input().split()))

    print(alt(t,n))
    
   
        
        

        

    
