t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    ans=0
    sign=2
    ma=-1
    mi=1
    if(l[0]>0):
        sign=0
 
    else:
        sign=1
     
    for j in range(n):
        if(sign==0):
            if(l[j]>ma):
                ma=l[j]
        elif(sign==1):
            if(mi==1):
                if(l[j]<mi):
                    mi=l[j]
            elif(l[j]>mi):
                    mi=l[j]
        if(j<n-1 and ((l[j]<0 and l[j+1]>0) or (l[j]>0 and l[j+1]<0))):
            if(sign==0):
                ans+=ma
                ma=-1
                sign=1
            else:
                ans+=mi
                sign=0
                mi=1
        if(j==n-1):
            if((l[j]>0 and l[j-1]>0) or (l[j]<0 or l[j-1]<0)):
                if(sign==0):
                    ans+=ma
                    ma=-1
                    break
                else:
                    ans+=mi
                    mi=1
                    break
            else:
                if(l[j]>0):
                    ans+=ma
                    break
                else:
                    ans+=mi
                    break
    print(ans)
    
            
            
