t=int(input())
for _ in range(t):
    n=int(input())
    a=[]
    b=[]
    c=[]
    a=list(map(int,input().split()))
    if(a[0]<0):
        f=0
    else:
        f=1
    i=0
    while(i!=n):
        if(f==0):
            if(a[i]<0):
                #print(a[i])
                c.append(a[i])
                i=i+1
            else:
                #print(c)
                b.append(max(c))
                c=[]
                f=1
                pass
                
        if(f==1):
            if(a[i]>0):
                c.append(a[i])
                i=i+1
            else:
                #print(c)
                b.append(max(c))
                c=[]
                f=0
                pass
    if(len(c)>0):
        b.append(max(c))
    print(sum(b))