t=(int)(input())
for weer in range(t):
    n=(int)(input())
    li=list(map(int,input().split()))
    lis=[1]*n
    prev=0
    temp=[]
    i=0
    for i in range(1,n):
        lis[i]=lis[i-1]
        if li[i]*li[i-1]<0:
            lis[i]=lis[i-1]+1
    temp=[]
    prev=-1
    c=1
    ma=li[0]
    for i in range(n):
        if lis[i]==c+1:
            c+=1
            temp.append(ma)
            ma=li[i]
        else:
            ma=max(ma,li[i]) 
    temp.append(ma)        
    
    #print(lis,temp)    
    print(sum(temp))
