t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    x=[]
    c=0
    d=0
    for j in range(len(l)):
        if l[j]>0 :
            d=0
            if c>0:
                if x[-1]<=l[j]:
                    x[-1]=l[j]
                    
                
            else:
                x.append(l[j])
            c=c+1
        else:
            c=0
            if d>0:
                if x[-1]<=l[j]:
                    x[-1]=l[j]
            else:
                x.append(l[j])
            d=d+1
    #print(x)
    print(sum(x))
