t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    count=0
    if(l[0]<0):
        flag=1
    else:
        flag=0
    m=0
    s=0
    for j in range(n):
        if(l[j]<0):
            if(flag==1):
                s+=m
                count=0
                
            if(count==0):
                m=l[j]
            else:
                if(m<l[j]):
                    m=l[j]
            count+=1 
            flag=0
        else:
            if(flag==0):
                count=0
                s+=m
            if(count==0):
                m=l[j]
            else:
                if(m<l[j]):
                    m=l[j]
            count+=1 
            flag=1 
    s+=m
    print(s)
            
            
            
        
    