def pos(i,sum):
    m=a[i]
    while i<n and a[i]>0:
        
        m=max(m,a[i])
        i+=1
    sum+=m
    return(i,sum)
def neg(i,sum):
    m=a[i]
    while i<n and a[i]<0:
        
        m=max(m,a[i])
        i+=1
    sum+=m
    return(i,sum)

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    sum=0
    while i<n:
        if a[i]>0:
            i,sum=pos(i,sum)
        elif a[i]<0:
            i,sum=neg(i,sum)
    print(sum)
        
        