tt=int(input())
while tt>0:
    m=int(input())
    l=list(map(int,input().split()))
    p,n='#','#'
    if l[0]>0:
        s=1
        p=l[0]
    else:
        s=-1
        n=l[0]
    q=0
    i=1
    while i<m:
        if l[i]>0:
            t=1
        else:
            t=-1
        if s>0 and t>0:
            p=max(p,l[i])
        elif s<0 and t<0:
            n=max(n,l[i])
        elif s<0 and t>0:
            q+=n
            n='#'
            p=l[i]
            s=1
        elif s>0 and t<0:
            q+=p
            p='#'
            n=l[i]
            s=-1
        i+=1
    if p!='#':
        q+=p
    else:
        q+=n
    print(q)
    tt-=1

