t=int(input())
for _ in range(t):
    n = int(input())
    li = list(map(int,input().split()))
    res=[]
    i=0
    while i<n:
        temp=[]
        if(li[i]>=0):
            while(i<n and li[i]>=0):
                temp.append(li[i])
                i+=1
        else:
            while(i<n and li[i]<0):
                temp.append(li[i])
                i+=1
        res.append(temp)

    sol=0
    
    for x in res:
        sol+=max(x)

    print(sol)