for _ in range(int(input())):
    n=int(input())
    A=list(map(int,input().split()))
    ans=0;ne=0
    for i in range(n):
        if(A[i]<0):
            ne+=1
    if(ne==n):
        print(max(A))
        continue
    elif(ne==0):
        print(max(A))
        continue
    N=[]
    P=[]
    for i in range(0,n):
        if(A[i]<0):
            N.append(A[i])
            if(len(P)==0):
                continue
            ans+=max(P)
            P=[]
        if(A[i]>0):
            P.append(A[i])
            if(len(N)==0):
                continue
            ans+=max(N)
            N=[]
    if(len(P)!=0):
        ans+=max(P)
    if(len(N)!=0):
        ans+=max(N)
    print(ans)
