t = int(input())
for i in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    summ = 0
    j = 0
    prev = 0
    if(arr[0]>0):
        prev = 1
    while(j<n):
        val = arr[j]
        if(prev ==0 and val<0):
            k  = j+1
            m = val
            while(k<n and arr[k]<0):
                if(arr[k]>m):
                    m = arr[k]
                k+=1
            summ+=m
            if(k==n):
                break
            j = k
        else:
            k = j+1
            m = val
            while(k<n and arr[k]>0):
                if(arr[k]>m):
                    m = arr[k]
                k+=1
            summ+=m
            if(k==n):
                break
            j = k
        if(prev==0):
            prev =1
        else:
            prev =0 
    print(summ)


