for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    if(l[0]>0):
        p=0
    else:
        p=1
    ans =[]
    k =0
    ma = -(10**9+1)
    while(k<n):
        
        if(p==0):
            if(l[k]>0):
                ma = max(l[k],ma)
                k+=1
            else:
                ans.append(ma)
                ma = -(10**9+1)
                p=1
                
        else:
            if(l[k]<0):
                ma = max(ma,l[k])
                k+=1
            else:
                p=0
                ans.append(ma)
                ma = -(10**9+1)
    ans.append(ma)

    
    print(sum(ans))
            
            