t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    ans=[]
    sum1=0
    i=0
    while(i<n):
        temp=[]
        j=i
        if(l[i]<0):
            while(j<n and l[j]<0):
                temp.append(l[j])
                j+=1
        if(l[i]>0):
            while(j<n and l[j]>0):
                temp.append(l[j])
                j+=1
        ans.append(temp)
        i=j

    for i in ans:
        sum1+=max(i)

    print(sum1)
    
    
            
