def sol(n,l):
    val=l[0]
    
    max_=l[0]
    i=1
    sum=0
    while i<n :
        if (l[i]>0 and val>0) or (l[i]<0 and val<0):
            max_=max(max_,l[i])
        else:
            sum+=max_
            max_=l[i]
        val=l[i]
        i+=1
        
    sum+=max_
    return sum
        
        
        

for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    print(sol(n,l))