
t=int(input())
for i in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    j=0
    s=[]
    z=[]
    while(j<n):
        count=0
        while(j<n and x[j]>0):
            z.append(x[j])
            j=j+1
            count+=1
            continue
        if(count>0):
            s.append(max(z))
        z=[]
        count=0
        while(j<n and x[j]<0):
            z.append(x[j])
            j=j+1
            count=count+1
            continue
        if(count>0):
            s.append(max(z))
    print(sum(s))