T=int(input())
for i in range(T):
        n=int(input())
        l=list(map(int,input().split()))
        lf=[]
        j=0
        su=0
        while(j<n):
                #print(j,"lo")
                c=0
                if(l[j]<0):
                        s=-10000000000
                        k=j
                        while(k<n and l[k]<0):
                                if(l[k]>s):
                                        s=l[k]
                                        
                                k=k+1
                                c=c+1
                        j=j+c
                else:
                        s=-10000000000
                        k=j
                        while(k<n and l[k]>=0):
                                if(l[k]>s):
                                        s=l[k]
                                        
                                k=k+1
                                c=c+1
                        j=j+c
                su=su+s
        print(su)
                        
