t = int(input())
array = [] 
for i in range(t):
    n = int(input())  
    array.append(n)
    arr = list(map(int,input().split())) 
    array.append(arr)

def alt_subs(n, array):
    arr = []
    count = 0
    for i in range(1, n):
        if (array[i-1] > 0 and array[i] < 0) or (array[i-1] < 0 and array[i] > 0):
           if count == 0 or array[i-1] > arr[count-1]: 
               arr.append(array[i-1])
               count += 1
           arr.append(array[i])
           count += 1
        else:
            if count == 0:
                if array[i-1] > array[i]:
                    arr.append(array[i-1])
                    count += 1
                else:
                    arr.append(array[i])
                    count += 1
            elif array[i] > arr[count-1]:
                arr[count-1] = array[i]
    
    if len(arr) == 0:
        arr.append(max(array))
      
    return sum(arr)
    
for i in range(0, t*2, 2):
    n = array[i]
    arr = array[i+1]
    print(alt_subs(n, arr))
    