def sign(n):
    return abs(n) // n

t = int(input())
for case in range(t):
    n = int(input())
    numbers = [int(x) for x in input().split()]

    cur_state = sign(numbers[0])

    numbers.append(sign(numbers[n-1])*-1)
    cur_set = []
    total = 0

    for i in range(n+1):
        k = numbers[i]
        if sign(k) == cur_state:
            cur_set.append(k)
        else:
            copycur_set = cur_set.copy()
            total += max(copycur_set)
            cur_state = cur_state * -1
            cur_set = [k]
            
    print (total)
            
            
        
