t=int(input())
for i in range(t):
        p=int(input())
        A=list(map(int,input().split()))
        su=0
        f1,f2=-1,-1
        fv1,fv2=-1,-10**9
        ans=0
        last=2
        for i in range(len(A)):
                if A[i]>=0:
                        
                        if A[i]>fv1:
                                f1=i
                                fv1=A[i]
                        if last==4 :
                                ans+=fv2
                                fv2=-10**9
                        last=3
                        
                        #
                if A[i]<0:
                        
                        if A[i]>fv2:
                                f2=i
                                fv2=A[i]
                        if last==3:
                                ans+=fv1
                                fv1=-1
                        last=4
                       
                #print(ans)
                #print(fv1,fv2)
        if last==4 :
                ans+=fv2
        if last==3:
                ans+=fv1
        print(ans)
        #print()
