res=[]
for _ in range(int(input())):
    input()
    x=[]
    y=[]
    for a in map(int,input().split()):
        n,m=len(x),len(y)
        if a<0:
            if n%2:
                x[-1]=max(x[-1],a)
            else:
                x+=a,
            if m%2:
                y+=a,
            elif m:
                y[-1]=max(y[-1],a)
        else:
            if m%2:
                y[-1]=max(y[-1],a)
            else:
                y+=a,
            if n%2:
                x+=a,
            elif n:
                x[-1]=max(x[-1],a)
    n,m=len(x),len(y)
    if n>m:res+=sum(x),
    elif m>n:res+=sum(y),
    else:res+=max(sum(x),sum(y)),
print('\n'.join(map(str,res)))