t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    ans=0
    i=0
    while(i<n):
        if(l[i]>0):
            j=i
            ma=l[i]
            while(j<n and l[j]>0):
                ma=max(ma,l[j])
                j+=1
            ans+=ma
            i=j-1
        else:
            j=i
            ma=l[i]
            while(j<n and l[j]<0):
                ma=max(ma,l[j])
                j+=1
            ans+=ma
            i=j-1
        i+=1
    print(ans)