for _ in range(int(input())):
    c=0
    p1=0
    p2=-10**9
    c1=0
    c2=0
    n = int(input())
    l = list(map(int,input().split()))
    for i in range(len(l)):
        if l[i]>0:
            c1+=1
            if l[i]>p1:
                p1=l[i]
            if c2>0:
                c+=p2
                p2=-10**9
            c2=0
        elif l[i]<0:
            c2+=1
            if l[i]>p2:
                p2=l[i]
            if c1>0:
                c+=p1
                p1=0
            c1=0
    if c1!=0:
        c+=p1
    if c2!=0:
        c+=p2
    print(c)
            
            
    