inf1=100000000000
inf2=-100000000000
t=int(input())
while t:
    n=int(input())
    l=list(map(int,input().split()))
    flag=0
    pre=0
    ans=0
    for i in range(n):
        if flag==0:
            if l[i]<0:
                flag=1
            else:
                flag=2
            pre=l[i]
        elif flag==1:
            if l[i]<0:
                if l[i]>pre:
                    pre=l[i]
            else:
                ans+=pre
                pre=l[i]
                flag=2
        elif flag==2:
            if l[i]>0:
                if l[i]>pre:
                    pre=l[i]
            else:
                ans+=pre
                pre=l[i]
                flag=1
    print(ans+pre)
    t-=1