def is_positive(a):
    return False if a < 0 else True


n = int(input())
for i in range(n):
    num = int(input())
    my_list = list(map(int, input().split()))
    if num == 1:
        print(my_list)
    else:
        current_taken = my_list[0]
        new_list = []
        for n in range(len(my_list) - 1):
            if is_positive(my_list[n]) == is_positive(my_list[n + 1]):
                current_taken = max(my_list[n], my_list[n + 1])
            else:
                new_list.append(current_taken)
                current_taken = my_list[n + 1]
        new_list.append(current_taken)
        print(sum(new_list))
