for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    x=0
    z=0
    for i in range(n):
        if(i==0):
            x=l[i]
            if(l[i]<0):
                f=2
            else:
                f=4
        elif(f==4):
            t=l[i]
            if(l[i]<0):
                z=z+x
                x=l[i]
                f=2
            else:
                if(x<t):
                    x=t
        else:
            t=l[i]
            if(l[i]>0):
                z=z+x
                x=l[i]
                f=4
            else:
                if(x<t):
                    x=t
    print(z+x)
        
            