for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    i=0
    ans=0
    while i<n:
            mx = -99999999999999
            while i<n and arr[i]>0:
                mx=max(mx,arr[i])
                i+=1
            if mx!=-99999999999999:
                ans+=mx
            mx = -99999999999999
            while i<n and arr[i]<0:
                mx = max(mx,arr[i])
                i+=1
            if mx!=-99999999999999:
                ans+=mx
    print(ans)