t = int(input())
for i in range(t):
    n = int(input())
    x = list(map(int,input().split()))
    j=1
    ans = 0
    locm = x[0]
    if n==1:
        print(x[0])
    else:
        while j<n:
            if(x[j-1]*x[j]>0):
                if x[j]>locm:
                    locm=x[j]
            else:
                ans+=locm
                locm=x[j]
            j+=1
        ans+=locm
        print(ans)
            