from sys import *
input=stdin.readline
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    mx=0
    mxn=-9999999999
    fp=0
    fn=0
    final=[]
    for i in range(n-1):
        if (l[i]>0 and l[i+1]>0):
            mx=max(mx,l[i])
            mx=max(mx,l[i+1])
            
        elif (l[i]<0 and l[i+1]<0):
            mxn=max(mxn,l[i])
            mxn=max(mxn,l[i+1])
            
        else:
            if l[i]>0:
                final.append(max(l[i],mx))
                mx=0
            else:
                final.append(max(l[i],mxn))
                mxn=-9999999999
            
                
    if l[n-1]>0 and l[n-2]>0:
        final.append(max(mx,l[n-1]))
    elif l[n-1]<0 and l[n-2]<0:
        final.append(max(mxn,l[n-1]))
    else:
        final.append(l[n-1])
                
                
    #print(final)
    print(sum(final))
    
                