t= int(input())

while t:
    t-=1
    n = int(input())
    arr = [int(i) for i in input().split()]
    posi = []
    nega = []
    i=0
    j=1
    while i<n and j<n :
        if arr[i] > 0 and arr[j]>0 :
            while i<n and j<n and arr[j]>0 :
                j+=1
            posi.append(arr[i:j])
            i = j
        elif arr[i] > 0 and arr[j]<0 :
            posi.append([arr[i]])
            i = j
        elif arr[i]<0 and arr[j]<0 :
            while i<n and j<n and arr[j]<0 :
                j+=1
            nega.append(arr[i:j])
            i = j
        elif arr[i]<0 and arr[j]>0 :
            nega.append([arr[i]])
            i = j
    
    ans = sum(list(map(max , posi))) + sum(list(map(max , nega)))
    print(ans)

    