t= int(input())
for i in range(t):
    a=int(input())
    l=list(map(int,input().split()))
    p=0
    n=0
    sum=0
    r=0
    for j in l:
        if(p==0 and j>0):
            r=j
            sum=sum+j
            p=1
            n=0
        elif(n==0 and j<0):
            r=j
            sum=sum+j
            n=1
            p=0
        elif((p==1 or n==1) and j>r):
            sum=sum-r
            sum=sum+j
            r=j
    print(sum)
        
        
        
        
