t= int(input())

i=0
while(i<t):
    n=int(input())
    arr = list(map(int, input().split()))
    sum,size,j,tmp=0,0,0,0
    while(j<n):
        if(j<n and arr[j]<0):
            tmp=-100000000000000000
            while ( j<n and arr[j]<0 ):
                tmp=max(tmp,arr[j])
                j+=1
            size+=1
            sum+=tmp
            tmp=-10000000000000000
        if (j<n and arr[j]>0):
            while(j<n and arr[j]>0):
                tmp=max(tmp,arr[j])
                j+=1
            size+=1
            sum+=tmp
    print(sum)
    i+=1
