inf=int(-1e18)
for _ in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    maxlen,s,f=0,0,a[0]>0
    start=0
    maxi=inf
    while start<n:
        j=start
        while j<n:
            if not f and a[j]>0: break
            if f and a[j]<0: break
            maxi=max(maxi,a[j])
            j+=1
        s+=maxi
        f^=1
        start=j
        if maxi!=inf: maxlen+=1
        maxi=inf
        
    print(s)
