# cook your dish here
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if(True):
        l1=[]
        m=0
        f=1
        for i in range(n):
            if(l[i]>0):
                m=max(m,l[i])
                f=1
            elif(f==1):
                l1.append(m)
                m=0
        if(f==1):
            l1.append(m)
        f=1
        p=0
        for i in range(n):
            if(l[i]<0 and f==1 and p==0):
                m1=l[i]
                f=0
                p=1
            elif(f==0 and l[i]<0 and p==1):
                m1=max(m1,l[i])
            elif(f==0 and p==1):
                l1.append(m1)
                f=1
                p=0
        if(f==0 and p==1):
            l1.append(m1)
        #print(*l1)    
        print(sum(l1))
    
        