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

