t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    count=0
            
    prev=arr[0]
    maxpo=arr[0]
    maxne=min(arr)
    sum1=0
    x=0
    y=0
    for i in range(1,n):
        if(arr[i]>0):
            if(prev>0):
                if(y==0):
                    maxpo=prev
                if(maxpo<arr[i]):
                    maxpo=arr[i]
                    prev=arr[i]
                    y=1
            else:
                sum1=sum1+prev
                maxpo=arr[i]
                prev=arr[i]
                y=0
                
        elif(arr[i]<0):
            if(prev<0):
                if(x==0):
                    maxne=prev
                if(maxne<arr[i]):
                    maxne=arr[i]
                    prev=arr[i]
                    x=1
            else:
                sum1=sum1+prev
                maxne=arr[i]
                prev=arr[i]
                x=0
    sum1=sum1+prev
    print(sum1)