for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    s=0
    while i<n-1:
        if a[i]>0:
            if a[i+1]<0:
                s+=a[i]
            else:
                if a[i]>a[i+1]:
                    a[i+1]=a[i]
        else:
             if a[i+1]>0:
                 s+=a[i]
             else:
                 if a[i]>a[i+1]:
                     a[i+1]=a[i]
        i+=1
    s+=a[n-1]
    print(s)
    
        
            
                
        
           
        
