t=int(input())
for _ in range(t):
    n=int(input())
    
    li=list(map(int,input().split()))
    sum=0
    i=0
    while(i!=len(li)):
        if(li[i]<0 ):
            minneg=li[i]
            while(i<len(li) and li[i]<0):
                minneg=max(minneg,li[i])
                i=i+1
            sum=sum+minneg
        else:
            minneg=li[i]
            while(i<len(li) and li[i]>0):
                minneg=max(minneg,li[i])
                i=i+1
            sum=sum+minneg
    print(sum)
            
            
            
    