T=int(input())
for i in range(T):
    N=int(input())
    ar=list(map(int,input().split()))
    r=0
    sm=0
    prevN=float('inf')
    prevP=float('-inf')
    while r<len(ar):
        if ar[r]<0:
        #    print(sm)
            if prevN!=float('inf'):
                
                curN=max(curN,ar[r])
            else:
                curN=ar[r]
                prevN=ar[r]
            if prevP!=float('-inf'):
                sm+=curP

            prevP=float('-inf')
            curP=float('-inf')
        else:
            if prevP ==float('-inf'):
                prevP = ar[r]
                curP=ar[r]
            else:
                curP=max(ar[r],curP)      
            
            if prevN!=float('inf'):
                sm+=curN
        
          
            prevN=float('inf')
            curN=float('inf')
        r+=1
    
    
    if curN!=float('inf'):
             sm+=curN
    if curP!=float('-inf'):
         sm+=curP
    print(sm)        
    
    