t = int(input())

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

    prev_sign = 0
    prev_val = 0
    prev_max = 0
    sum = 0
    for a in input().split():
        a = int(a)
        sign = 1 if a > 0 else 2
        if sign != prev_sign:
            sum += prev_max
            prev_max = a
            prev_sign = sign
            continue

        prev_max = max(a, prev_max)
    sum += prev_max
    print(sum)
