t = int(input())

for _ in range(t):
    n = int(input())

    a = list(map(int, input().split()))

    max_sum = a[0]
    max_lenght = 1
    counter = 1
    cur_min = a[0]
    sum = a[0]
    for i in range(1,len(a)):
        # if a[i-1] > 0 and a[i] < 0 or \
        #     a[i-1] < 0 and a[i] > 0:
        #     counter += 1
        #     sum += a[i]
        # else:
        #     if max_lenght == counter:
        #         if max_sum <= sum:
        #             max_sum = sum
        #     if max_lenght < counter:
        #         max_sum = sum
        #         max_lenght = counter
        #     counter = 1
        #     sum = a[i]
        def func(i):
            global sum, a, cur_min
            if a[i-1] < 0 and a[i] < 0 and cur_min < a[i]:
                sum -= cur_min
                sum += a[i]
                cur_min = a[i]
                # print(f'1) i: {i} sum: {sum}')
            elif a[i-1] > 0 and a[i] > 0 and cur_min < a[i]:
                sum -= cur_min
                sum += a[i]
                cur_min = a[i]
                # print(f'2) i: {i} sum: {sum}')
            elif a[i-1] < 0 and a[i] > 0 or \
                    a[i-1] > 0 and a[i] < 0:
                sum += a[i]
                cur_min = a[i]
                # print(f'3) i: {i} sum: {sum}')

        func(i)

    # func(-1)
    print(sum)

