t=int(input())
for i in range(t):
    n=int(input())
    lis=list(map(int , input().split()))
    neg=0
    pos=0
    s=0
    j=0
    while(j<n):
        if(lis[j]<0):
            neg=lis[j]
            while(j<n and lis[j]<0 ):
                neg=max(neg , lis[j])
                j=j+1
            s=s+neg    
        else:
            pos=lis[j]
            while(j<n and lis[j]>0):
                pos=max(lis[j] , pos)
                j=j+1
            s=s+pos
        
            
    print(s)    
