t=int(input())
while(t):
    t-=1
    n=int(input())
    l=list(map(int,input().split()))
    sum=0
    i=0
    while(i<len(l)):
        curr=l[i]
        j=i
        while(j<n and l[i]*l[j]>0):
            curr=max(curr,l[j])
            j+=1
        sum+=curr
        i=j-1
        i+=1
    print(sum)
    