t=int(input())
for i in range(t):
    
    n=int(input())
    a=list(map(int, input().rstrip().split()))
    
    pos=0
    neg=0
    i=0
    while i <n:
        
        if a[i]>0:
            pos=a[i]
            j=i+1
        
            while j<n and a[j]>0:
                if a[j]>a[i]:
                    pos=a[j]
                j+=1
            neg+=pos
            i=j
            
        elif a[i]<0:
            
            pos=a[i]
            j=i+1
        
            while j<n and a[j]<0:
                if a[j]>a[i]:
                    pos=a[j]
                j+=1
            neg+=pos
            i=j
    print(neg)
        
            
            
                
        
        
    
    
    
    
    
    