def solve(a):
    max_ = a[0]
    prev_max = a[0]
    switch_counter = 0
    sum_ = 0

    for i in range(1, len(a)):
        current_item = a[i]
        previous_item = a[i-1]

        if (current_item > max_) & (current_item * previous_item >= 0):
            prev_max = max_
            max_ = current_item

        if current_item * previous_item < 0:

            sum_ += prev_max
            max_ = current_item
            prev_max = max_

            switch_counter += 1

            if i == len(a) - 1:
                sum_ += max_


    if switch_counter > 0:
        print(sum_)
    else:
        print(prev_max)

t = int(input())
for i in range(t):
    len_ = int(input())
    a = list(map(lambda x: int(x), input().split(' ')))
    solve(a)