for _ in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    boo=True if a[0]>0 else False
    a+=[0];ans=0;c=-100000000000
    #print(a,boo)
    for  i in a:
        if(boo and i<=0) or (not boo and i>=0):
            #print(i,c)
            ans+=c
            c=i
            boo^=True
            #print(boo)
        else:
            c=max(c,i)
        #print(ans,boo)
    print(ans)
            
