try:
    n=int(input())
    for i in range(n):
        k=int(input())
        A=list(map(int,input().split()))
        maxi=0
        g=0
        for j in range(1,n):
            if(A[j]*A[j-1]<0):
                print(A[g:j])
                maxi+=max(A[g:j])
                g=j
        maxi+=max(A[g:])
        print(maxi)
except:
    pass