st=''
def func(n,l):
    s=i=0
    while i<n:
        j=i
        m1=0
        m2=-1000000000
        while i<n and l[i]<0:
            m2=max(m2,l[i])
            i+=1
        if j!=i:
            s+=m2
        j=i
        while i<n and l[i]>0:
            m1=max(m1,l[i])
            i+=1
        if j!=i:
            s+=m1
    return s
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    st+=str(func(n,l))+'\n'
print(st)