if __name__=="__main__":
    t=int(input())
    for i in range(t):
        n=int(input())
        ar=list(map(int,input().split()))
        st=[ar[0]]
        ans=0
        for i in range(1,len(ar)):
            if((ar[i]>0 and st[-1]<0) or (ar[i]<0 and st[-1]>0)):
                ans+=st.pop()
                st.append(ar[i])
            else:
                if(st[-1]<ar[i]):
                    st.pop()
                    st.append(ar[i])
        if(len(st)!=0):
            ans+=st[-1]
        print(ans)
