t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    max1=-10**100
    sum1=0
    for i in range(0,n):
        if(l[i]>0):
            f1=1
        else:
            f1=-1
        if(abs(f-f1)==2):
            sum1=sum1+max1
            max1=-10**100
        max1=max(max1,l[i])
        f=f1
    print(sum1+max1)
