inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
stent=lambda : [i for i in inp()]
ma=max
l=len

t=iinp()
for _ in range(t):
    n=iinp()
    numeros=lient()
    pos=[]
    neg=[]
    res=0
    for i in numeros:
        if i>0: 
            if l(neg)>0:
                res+=ma(neg)
                neg=[]
            pos.append(i)
        else:
            if l(pos)>0:
                res+=ma(pos)
                pos=[]
            neg.append(i)
    if l(neg)>0:
            res+=ma(neg)
    if l(pos)>0:
            res+=ma(pos)
    print(res)