for i in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if(l[0]<0):
        sign=-1
    else:
        sign=1    
    sum1=l[0]
    tr=0
    tr1=0
    for i in range(len(l)):
        if(l[i]>0):
            tr1=l[i]
            break
    for i in range(len(l)):
        if(l[i]<0):
            tr=l[i]
            break

    
    
    for i in range(1,len(l)):
        if(l[i]>0):
            if(sign==-1):
                sign=1
                sum1+=l[i]
                tr1=l[i]
            else:
                if(l[i]>=tr1):
                    sum1+=l[i]-tr1
                    tr1=l[i]
        else:
            if(sign==1):
                sign=-1
                sum1+=l[i]
                tr=l[i]
            else:
                if(l[i]>=tr):
                    sum1+=l[i]-tr
                    tr=l[i]    
                    
    print(sum1)                
