def fun(n):
    a=[int(x) for x in input().split()]
    ans=0
    m_p=0
    m_n=-float("inf")
    for i in range(n):
        if i==n-1:
            if a[i-1]*a[i]>0:
                if a[i]>0:
                    if a[i]>m_p:
                        m_p=a[i]
                    ans+=m_p
                else:
                    if a[i]>m_n:
                        m_n=a[i]
                    ans+=m_n
            else:
                ans+=a[i]
            break
        if a[i]*a[i+1]>0:
            if a[i]>0:
                if a[i]>m_p:
                    m_p=a[i]
            else:
                if a[i]>m_n:
                    m_n=a[i]
        else:
            if a[i]>0:
                if a[i]>m_p:
                    m_p=a[i]
                ans+=m_p
                m_p=0
            else:
                if a[i]>m_n:
                    m_n=a[i]
                ans+=m_n
                m_n=-float("inf")
    print(int(ans))



    

t=int(input())
for i in range(t):
    n=int(input())
    fun(n)