n=int(input())
for x in range(n):
    m=int(input())
    l1=list(map(int, input().split()))
    l2=[]
    
    i=0
    while i<m:
        j=i
        if l1[i]>0:
            while l1[i]>0:
                i+=1
                if i==m:
                    break
            l2.append(max(l1[j:i]))
        elif l1[i]<0:
            while l1[i]<0:
                i+=1
                if i==m:
                    break
            l2.append(max(l1[j:i]))
    print(sum(l2))