m=10**9+7
t = int(input())
while(t):
    t-=1
    n = int(input())
    l = list(map(int,input().split()))
    ans=0
    i=0
    while i<n:
        lmax=0
        if i<n and l[i]>0:
            while i<n and l[i]>0:
                if l[i]>lmax:
                    lmax=l[i]
                i+=1    
            ans+=lmax
        if i<n and l[i]<0:
            lmax=-10**9
            while i<n and l[i]<0:
                if l[i]>lmax:
                    lmax=l[i]
                i+=1
            ans+=lmax
    print(ans)    