
t = int(input())

for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]

    prev_sign = a[0] > 0
    prev = a[0]
    s = a[0]
    for x in a[1:]:
        sign = x > 0
        if sign == prev_sign:
            if x > prev:
                s += x - prev
                prev = x
        else:
            prev_sign = sign
            prev = x
            s += x

    print(s)
