#p.sort(key=lambda x:(-x[0],-x[1]))
#alp='#abcdefghijklmnopqrstuvwxyz'
for t in range(int(input())):
    n=int(input())
    #a,b=map(int,input().split())
    l=list(map(int,input().split()))
    arr=[-float('inf')]*(n+5)
    arr[0]=max(arr[0],l[0])
    count=[0]*(n+5)
    count[0]=1
    if l[0]>0:
        last=1
    else:
        last=-1
    for i in range(1,n):
        if (l[i]>0 and last<0) or (l[i]<0 and last>0):
            count[i]=count[i-1]+1
            last*=(-1)
        else:
            count[i]=count[i-1]
        arr[count[i]-1]=max(arr[count[i]-1],l[i])
    x=count[n-1]
    #print(count[:n])
    print(sum(arr[:x]))
    '''ans=0
    for i in range(x):
        ans+=arr[i]
    print(ans)'''
    
    
    