for r in range(int(input())):
    n=int(input())
    u,r,x,z=1,1,0,0
    p=[]
    y,k,t=0,0,0
    l=list(map(int,input().split()))
    for i in range(len(l)):
        if l[i]>0:
            x=1
            t=t+y
            y=0
            r=1
            if u==1:
                u=0
                k=l[i]
                if i==len(l)-1:
                    p.append(k)
            else:
                if l[i]>k:
                    k=l[i]
                    u=0
                if i==len(l)-1:
                    p.append(k)
        else:
            z=1
            u=1
            t=t+k
            k=0
            if r==1:
                y=l[i]
                r=0
                if i==len(l)-1:
                        p.append(y)
            else:
                
                if l[i]>y:
                    y=l[i]
                    r=0
                if i==len(l)-1:
                    p.append(y)
    if p[0]>0 and l[0]>0 and x==1 and z==1:
        print(t,)
    elif p[0]<0 and l[0]<0 and x==1 and z==1:
        print(t)
    else:
        print(t+p[0])

        

        
        
        