"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""



T=int(input())
for _ in range(0,T):
    n=int(input())
    s=[int(x) for x in input().split()]
    ans=0
    mx=s[0]
    for i in range(1,len(s)):
        if(s[i]<0 and s[i-1]<0):
            mx=max(mx,s[i])
        elif(s[i]>0 and s[i-1]>0):
            mx=max(mx,s[i])

        else:
            ans+=mx
            mx=s[i]
    ans+=mx

    print(ans)
    
