for _ in range(int(input())):
    j=int(input())
    a=list(map(int,input().split()))
    l=0
    x=-10000000000
    k=0
    sum1=0
    p=True
    n=True
    t=[]
    m=[]
    for i in range(0,j):
        if(a[i]>=l):
           l=a[i]
           p=False
           if(n==False):
                m.append(k)
                n=True
                k=0
                x=-10000000000
        elif(a[i]>x and a[i]<0):
            x=a[i]
            k=x
            n=False
            if(p==False):
                t.append(l)
                p=True
                l=0
    print(sum(t)+sum(m)+l+k)
            
