for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    if a[0]>0:
        prev="pos"
    else:prev="neg"
    temp=a[0]
    cur=prev
    ans=[]
    i=1
    while i<n:
        if a[i]>0:cur="pos"
        else:cur="neg"
        if cur==prev:
            temp=max(temp,a[i])
            i+=1
        else:
            ans.append(temp)
            prev=cur
            temp=a[i]
    ans.append(temp)
    print(sum(ans))
            
        
            
            
        
