def is_element_suits(prev, current, sum_of):
    if current * prev < 0: 
        return (True, sum_of + current)
    elif current > prev:
        return (True, sum_of - prev + current)
    return (False, sum_of)


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

    list_positive = [-1]
    list_negative = [1]
    sum_positive = 0
    sum_negative = 0

    for element in a:
        # Is element suits for positive? 
        (is_opposite, sum_positive) = is_element_suits(list_positive[-1], element, sum_positive)
        if is_opposite:
            list_positive.append(element) 
        
        # Is element suits for negative? 
        (is_opposite, sum_negative) = is_element_suits(list_negative[-1], element, sum_negative)
        if is_opposite:
            list_negative.append(element)

    if len(list_positive) > len(list_negative):
        print(sum_positive)
    elif len(list_positive) < len(list_negative):
        print(sum_negative)
    else:
        print(max(sum_negative, sum_positive))
        
