t = int(input())


def sign(number):
    return number / abs(number)


for i in range(t):
    n = int(input())
    numbers = list(map(int, input().split()))

    answer = 0
    current_subseq = []
    current_sign = numbers[0]
    for x in numbers:
        if current_sign * x > 0:
            current_subseq.append(x)
        else:
            answer += max(current_subseq)
            current_sign *= -1
            current_subseq = [x]

    answer += max(current_subseq)
    print(answer)
