t=int(input())
for i in range(1,t+1):
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    s=0
    while(i<n):
        a=l[i]
        k=0
        if l[i]<0:
            k=1
        i+=1
        while(i<n):
            if k==1:
                if l[i-1]<0 and l[i]<0:
                    a=max(l[i],a)
                else:
                    i-=1
                    break
            else:
                if l[i-1]>0 and l[i]>0:
                    a=max(l[i],a)
                else:
                    i-=1
                    break
            i+=1
        s+=a
        i+=1
    print(s)
                    
