def num_input():
    return map(int,input().split())

def list_input():
    return list(num_input())
    
for t in range(int(input())):
    n = int(input())
    arr = list_input()
    sum = 0
    i = 0
    while i < n:
        j = i+1
        max = arr[i]
        sign = False
        if arr[i] < 0:
            sign = True
        while j < n:
            if sign:
                if arr[j] < 0:
                    if max < arr[j]:
                        max = arr[j]
                else:
                    break
            else:
                if arr[j] > 0:
                    if max < arr[j]:
                        max = arr[j]
                else:
                    break
            j += 1
        temp = max
        if sign:
            max = 0
            while j < n and arr[j] > 0:
                if max < (arr[j]):
                    max = arr[j]
                j += 1
            sum += (temp+max)
        else:
            min = -1*(10**10)
            while j < n and arr[j] < 0:
                if min < (arr[j]):
                    min = arr[j]
                j += 1
            if min != (-1*(10**10)):
                sum += (temp+min)
            else:
                sum += temp
        i = j
        
    print(sum)
        
        
        
        
        