def solve(a):
    max_ = a[0]
    prev_max = a[0]
    switch_counter = 0
    if len(a) > 1:
        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:
                if (current_item > max_):
                    prev_max = max_
                sum_ += max_
                max_ = current_item
                prev_max = max_

                switch_counter += 1

            if i == len(a) - 1:
                if current_item >= max_:
                    max_ = current_item
                sum_ += max_
    else:
        sum_ = a[0]


    print(sum_)



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