import sys,bisect
input=sys.stdin.readline
T=int(input())
for _ in range(T):
    n=int(input())
    A=list(map(int,input().split()))
    s,mn,mp,flag1,flag2=0,0,0,0,0
    for i in range(n):
        if (A[i]<0):
            if (flag2==1):
                s=s+A[i]
                flag2=0
                mn,mp=A[i],0
            else:
                flag1=1
                if (A[i]>mn or mn==0):
                    s=s+A[i]-mn
                    mn=A[i]

        elif(A[i]>0):
            if (flag1==1):
                s=s+A[i]
                flag1=0
                mp,mn=A[i],0
            else:
                flag2=1
                if (A[i]>mp or mp==0):
                    s=s+A[i]-mp
                    mp=A[i]
        #print(s,mn,mp)
    print(s)
        
        
