def solve(a):
    max_ = a[0]
    prev_max = a[0]
    sum_ = 0
    switch_counter = 0
    for i in range(1,len(a)):
        item = a[i]
        previous_item = a[i-1]
        if item*previous_item < 0:
            switch_counter += 1
            prev_max = max_
            max_ = item
            if switch_counter == 1:
                sum_ += sum([prev_max,max_])
            else:
                sum_ += max_
            #print(prev_max, max_)
        else:
            if (item > max_):
                max_ = item
    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)