# cook your dish here
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    ans=[a[0]]
    if a[0]>=0:
        last=1
    else:
        last=0
    
    i=1
    while i<n:
        if a[i]>=0 and last==1:
            ans[-1]=max(ans[-1],a[i])
        elif a[i]<0 and last==0:
            ans[-1]=max(ans[-1],a[i])
            
        else:
            ans.append(a[i])
            last=1-last
        i+=1
    
    print(sum(ans))