t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    e=l[0]
    k=1
    s=0
    for j in range(1,n):
        if l[j]*e<0:
            s+=e
            e=l[j]
            k+=1
        elif l[j]>e:
            e=l[j]
    s+=e
    print(s)
            
        
         
                       