for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,raw_input().split()))

    def solve(arr,n):
        if all(x>=0 for x in arr)==True or all(x<=0 for x in arr)==True:
            return max(arr)

        else:
            ans=0
            flag=False
     
            b=[arr[0]]
            for i in range(1,n-1):
                if arr[i-1]<0:
                    if arr[i]<0:
                        b.append(arr[i])
                    else:
                        ans+=max(b)
                        b=[arr[i]]
                else:
                    if arr[i]>=0:
                        b.append(arr[i])
                    else:
                        ans+=max(b)
                        b=[arr[i]]
            if arr[-2]<0:
                if arr[-1] < 0:
                    b.append(arr[-1])
                    ans+=max(b)
                else:
                    ans+=max(b)
                    ans+=arr[-1]
            else:
                if arr[-1] >= 0:
                    b.append(arr[-1])
                    ans+=max(b)
                else:
                    ans += max(b)
                    ans += arr[-1]


            return ans



    print(solve(arr,n))



