t=int(input())
for test in range(t):
    n=int(input())
    temp=input()
    temp=temp.split(" ")
    temp=list(map(int,temp))
    sign=temp[0]/abs(temp[0])
    res=[]
    i=0
    for x in temp:
        if x/abs(x)==sign:
            res.append(x)
            i+=1
            sign*=(-1)
        else:
            if x>res[i-1]:
                res[i-1]=x
    sum=0
    for x in res:
        sum=sum+x
    print(sum)