
for _ in range(int(input())):

    n=int(input())

    l=list(map(int,input().split()))

    su=i=mxx=0
    
    while i<=n-1:
        mxx=-pow(10,18)
        if l[i]>0:
            
            j=i
            while j<n and l[j] > 0 :
                if mxx<l[j]:
                    mxx=l[j]
                j+=1

            su+=mxx
            i=j

        else:
            j=i
            while(j<n and l[j]<0):
                if mxx<l[j]:
                    mxx=l[j]
                j+=1

            su+=mxx
            i=j

    print(su)