t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    sum1=0
    i=0
    while(i<n):
        curr=arr[i]
        j=i+1
        while(j<n):
            if((arr[i]>0 and arr[j]>0)or(arr[i]<0 and arr[j]<0)):
                curr=max(curr,arr[j])
                j+=1
            else:
                break
        i=j-1
        sum1+=curr
        i+=1
    print(sum1)
    