t=int(input())
while t>0:
    n=int(input())
    l=list(map(int,input().split()))
    
    sum=0
    positive=[]
    negative=[]
    for i in range(n-1):
        
        if l[i]>0 and l[i+1]<0:
            positive.append(l[i])
            sum+=max(positive)
            positive.clear()
        elif l[i]<0 and l[i+1]>0:
            negative.append(l[i])
            sum+=max(negative)
            negative.clear()
        elif l[i]>0:
            positive.append(l[i])
        else:
            negative.append(l[i])
    if (l[n-2]>0 and l[n-1]<0) or (l[n-2]<0 and l[n-1]>0):
        sum+=l[n-1]
    elif l[n-1]>0:
        positive.append(l[n-1])
        sum+=max(positive)
        positive.clear()
    else:
        negative.append(l[n-1])
        sum+=max(negative)
        negative.clear()
    '''
    print("posi=",positive)
    print("nega=",negative)
    print("sum=",sum) '''
    print(sum)
        
            
            
            
            
            
    
    t-=1
