t= input('')
for x in range(t):
    
    n= input('')
    a= map(int,raw_input('').split(' '))
    index=0    
    if a[0]>=0:
        curr='e'
    else:
        curr='o'
    k=0
    sum1=0
    while(index<n):
        if curr=='e':
            if a[index]>=0:
                k+=1
                
                max1=a[index]
                index+=1
                while(index<n and a[index]>=0):
                    max1=max(max1,a[index])
                    index+=1
                
                sum1+=max1
                curr='o'
            
        else:
            if a[index]<0:
                k+=1
                
                max1=a[index]
                index+=1
                while(index<n and a[index]<0):
                    if a[index]>max1:
                        max1= a[index]
                    index+=1
               
                sum1+=max1
                curr='e'
           
            
    print  sum1         
        
  