t=int(input())
for _ in range(0,t):
    n=int(input())
    mat=[int(z) for z in input().split()]
    dd=1
    cc=0
    if(mat[-1]>cc):
        mat.append(-1)
    else:
        mat.append(dd)
        
    n=n+dd
    
    pp=-2
    pn=-2
    mp=-1000000001
    mn=-1000000001
    mps=cc
    mns=cc
    res=cc
    for i in range(0,n):
        if mat[i]>0:
            mps=1
            if pp==(i-1):
                mp=max(mp,mat[i])
            else:
                if mns>0:
                    res+=mn
                mp=mat[i]
            pp=i
        else:
            mns=1
            if pn==(i-1):
                mn=max(mn,mat[i])
            else:
                if mps>0:
                    res+=mp
                mn=mat[i]
            pn=i
            
    print(res)