def solve():
    n=int(input())
    arr=[int(v) for v in input().split()]
    i=0
    j=0
    ans=0
    while i<n:
        add=arr[i]
        while j<n and (arr[j]<0)==(arr[i]<0):
            add=max(add,arr[j])
            j+=1
        ans+=add
        i=j
    print(ans)


t=int(input())
for _ in range(t):
    solve()
