k=int(input())
for x in range(k):
    m=int(input())
    l=list(map(int, input().split()))
    
    l2=[]
    
    
    
    i=0
    while i<m:
        j=i
        if l[i]>0:
            while l[i]>0:
                i=i+1
                if i==m:
                    break
            l2.append(max(l[j:i]))
        
        elif l[i]<0:
            while l[i]<0:
                i=i+1
                if i==m:
                    break
            
            l2.append(max(l[j:i]))

    print(sum(l2))