t=int(input())
while t:
    t=t-1
    n=int(input())
    l=list(map(int,input().split()))
    max_ending_here=0
    lp,ln=0,0
    for i in range(n):
        if l[i]<0 and i==0:
            sign='n'
            max_ending_here+=l[i]
            ln=l[i]
        elif l[i]>0 and i==0:
            sign='p'
            max_ending_here+=l[i]
            lp=l[i]
        else:
            if sign=='n' and l[i]>0:
                max_ending_here+=l[i]
                sign='p'
                lp=l[i]
            elif sign=='n' and l[i]<0:
                if l[i]>ln:
                    max_ending_here-=ln
                    max_ending_here+=l[i]
                    ln=l[i]
            elif sign=='p' and l[i]<0:
                max_ending_here+=l[i]
                sign='n'
                ln=l[i]
            elif sign=='p' and l[i]>0:
                if l[i]>lp:
                    max_ending_here-=lp
                    max_ending_here+=l[i]
                    lp=l[i]
    print(max_ending_here)