try:
    for _ in range(int(input())):
        n=int(input())
        l=list(map(int,input().split()))
        l.append(0)
        m=0
        sum=0
        for i in range(n):
            if((l[i]>0 and l[i+1]>0) or (l[i]<0 and l[i+1]<0)):
                m=max(l[i],l[i+1])
            else:
                if(m==0):
                    sum=sum+l[i]
                else:
                    sum=sum+m
                    m=0
        print(sum)        
except:
    pass