for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=0
    flag=0
    p=0
    q=0
    if a[0]>0:
        for i in range(1,n):
            if a[i]<0 and flag==0:
                flag=1
                p=i
            if flag==1 and a[i]>0:
                mi=max(a[p:i])
                ma=max(a[q:p])
                s+=mi+ma
                q=i
                flag=0
            if q==0 and flag==0 and i==n-1:
                s=max(a)
                break
            if i==n-1 and flag==1:
                s+=max(a[p:n])
                s+=max(a[q:p])
            elif i==n-1 and flag==0:
                s+=max(a[q:n])
    else:
        for i in range(1,n):
            if a[i]>0 and flag==0:
                flag=1
                p=i
            if flag==1 and a[i]<0:
                ma=max(a[p:i])
                mi=max(a[q:p])
                s+=mi+ma
                q=i
                flag=0
            if q==0 and flag==0 and i==n-1:
                s=max(a)
                break
            if i==n-1 and flag==1:
                s+=max(a[p:n])
                s+=max(a[q:p])
            elif i==n-1 and flag==0:
                s+=max(a[q:n])
    print(s)
        
                
                
