t=int(input())
while t>0:
    t-=1
    n=int(input())
    A=list(map(int,input().strip().split(' ')))
    sumA=0
    if A[0]>0:
        current="pos"
    else:
        current="neg"
    c=0
    if n==1:
        print(A[0])
    else:
        for i in range(1,n):
            if current=="pos":
                if A[i]>0:
                    pass
                else:
                    sumA+=max(A[c:i])
                    c=i
                    current="neg"
            else:
                if A[i]<0:
                    pass
                else:
                    sumA+=max(A[c:i])
                    c=i
                    current="pos"
            if current=="neg" and A[i]<0 and i==n-1:
                sumA+=max(A[c:])
            elif current=="pos" and A[i]>0 and i==n-1:
                sumA+=max(A[c:])
        print(sumA)


