t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if(a[0]>0):
        flag=0
        t1=0
        q=a[0]
        for i in range(1,n):
            if(a[i]<0):
                if(flag==1):
                    q=max(q,a[i])
                else:
                    t1+=q
                    flag=1
                    q=a[i]
            elif(a[i]>0):
                if(flag==0):
                    q=max(q,a[i])
                else:
                    t1+=q
                    flag=0
                    q=a[i]
        t1+=q
        print(t1)
    elif(a[0]<0):
        flag=0
        t1=0
        q=a[0]
        for i in range(1,n):
            if(a[i]>0):
                if(flag==1):
                    q=max(q,a[i])
                else:
                    t1+=q
                    flag=1
                    q=a[i]
            elif(a[i]<0):
                if(flag==0):
                    q=max(q,a[i])
                else:
                    t1+=q
                    flag=0
                    q=a[i]
        t1+=q
        print(t1)






