tc=int(input())
for eachi in range(tc):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    flag=0
    count=0
    if(a[0]<0):
        flag=1
    if(flag==0):
        i=0
        while(i<n):
            c=[]
            if(count%2==0):
                flg=0
                for j in range(i,n):
                    if(a[j]>=0):
                        c.append(a[j])
                    else:
                        flg=1;
                        i=j
                        break
                if(flg==0):
                    i=j+1
            else:
                flg=0
                for j in range(i,n):
                    if(a[j]>=0):
                        flg=1
                        i=j
                        break
                    else:
                        c.append(a[j])
                if(flg==0):
                    i=j+1
            count=count+1
            if(len(c)!=0):
                b.append(max(c))
            c=[]
    else:
        i=0
        while(i<n):
            c=[]
            if(count%2==1):
                flg=0
                for j in range(i,n):
                    if(a[j]>=0):
                        c.append(a[j])
                    else:
                        flg=1
                        i=j
                        break
                if(flg==0):
                    i=j+1
            else:
                flg=0
                for j in range(i,n):
                    if(a[j]>=0):
                        flg=1
                        i=j
                        break
                    else:
                        c.append(a[j])
                if(flg==0):
                    i=j+1
            
            count=count+1
            
            if(len(c)!=0):
                b.append(max(c))
            c=[]
    print(sum(b))
            
            
            