for _ in range( int(input())):
    x=int(input())
    l=list(map(int,input().split()))
    pos=0
    maxy=0
    miny=0
    sum=0
    for i in range(x):
        if(l[i]>0):
            if(pos==0):
                sum+=miny
            miny=-99999999999
            pos=1
            maxy=max(l[i],maxy)
        else:
            if(i==0):
                miny=-99999999999
            if(pos==1):
                sum+=maxy
            pos=0
            maxy=0
            miny=max(l[i],miny)
    sum+=maxy
    if(miny!=-99999999999):
        sum+=miny
    print(sum)



