n=int(input())
for i in range(n):
    ans=0
    m=int(input())
    a=list(map(int,input().split()))
    # l=0
    # r=0
    # for j in a:
    #     if j>0:
    #         r+=1
    #     else:
    #         l+=1
    # b=min(r,l)
    # mini=10**10
    maxi=-(10**10)
    for j in range(m-1):
        maxi=max(maxi,a[j])
        # mini=min(mini,a[j])
        if a[j]*a[j+1]<0:
            ans+=maxi
            # print(maxi)
            maxi=-(10**10)

    ans+=max(maxi,a[-1])
    print(ans)
