x=int(input())
for i in range(x):
    n=int(input())
    a=list(map(int,input().split()))
    t=0
    l=[]
    for i in range(n-1):
        
        if a[i]>0 :
            l.append(a[i])
            
            if a[i+1]<0:
                t+=max(l)
                l=[]         
        else:
            l.append(a[i])
            if a[i+1]>0:
                t+=max(l)
                l=[]
    if n>=2:
        if a[-1]*a[-2]>0:
            l.append(a[-1])
            t+=max(l)
        else:
            t+=a[-1]
        print(t)
    else:
        print(a[0])