t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    k=[]
    flag1=0
    flag2=0
    h=[]
    g=[]
    for i in range(n):
        if l[i]<0:
            if len(h)>0:
                k.append(max(h))
                h=[]
            g.append(l[i])
        elif l[i]>0:
            if len(g)>0:
                k.append(max(g))
                g=[]
            h.append(l[i])
    if len(h)>0:
        k.append(max(h))
    if len(g)>0:
        k.append(max(g))
    print(sum(k))
        
        
    