t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(x) for x in input().split()]
    
    ispos=True
    ans=0
    curr=0
    for x in a:
        if (x>0)!=ispos: #sign flip
            ans+=curr
            curr=x
        else:
            curr=max(curr,x)
        ispos=(x>0)
    ans+=curr
    print(ans)