t=int(input())
while(t):
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    s=0
    while(i<n):
        m1=-100000000000
        m2=-10000000000
        while(i<n and l[i]>0):
            if(l[i]>m1):
                m1=l[i]
            i+=1
        while(i<n and l[i]<0):
            if(l[i]>m2):
                m2=l[i]
            i+=1
        if(m1!=-100000000000):
            s+=m1
        if(m2!=-10000000000):
            s+=m2
    print(s)
    
        
        
    t-=1