for i in range(int(input())):
    n=int(input())
    nums=[int(i) for i in input().split()]
    s=0
    ps=1 if nums[0]>0 else 0
    pmax=nums[0]
    for i in range(1,n):
        if nums[i]>0:
            if ps==0:
                s+=pmax
                ps=1
                pmax=nums[i]
            else:
                if nums[i]>pmax:
                    pmax=nums[i]
        else:
            if ps==1:
                s+=pmax
                ps=0
                pmax=nums[i]
            else:
                if nums[i]>pmax:
                    pmax=nums[i]
    s+=pmax
    print(s)
    
    
