for _ in range(int(input())):
    m=int(input())
    l=list(map(int,input().split()))
    q=[]
    p=[]
    i=0
    res=0
    while(i<m):
        while(i<m and l[i]>0):
            q.append(l[i])
            i=i+1
        #print(q)    
            
        while(i<m and l[i]<0):
            p.append(l[i])
            i+=1
        #print(p)    
        if(len(q)==0):
            y=0
        else:    
            y=max(q)    
        
        if(len(p)==0):
            x=0
        else:    
            x=max(p)
        #print(";;;x",x)
        #print("////y",y)
        res=res+x+y
        #print("res",res)
        p=[]
        q=[]
        
    print(res)    
                
    