t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split()))
    r=[a[0]]
    c=[]
    for i in range(1,n):
        if a[i]<0 and r[len(r)-1]<0:
            r.append(a[i])
        elif a[i]<0 and r[len(r)-1]>0:
            c.append(r)
            r=[]
            r.append(a[i])
        elif a[i]>0 and r[len(r)-1]>0:
            r.append(a[i])
        elif a[i]>0 and r[len(r)-1]<0:
            c.append(r)
            r=[]
            r.append(a[i])
    c.append(r)
    s=0
    for i in c:
        s+=max(i)
    print(s)
        
            
            
        
