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