def sign(x):
    return 1 if x > 0 else -1

def solve(n, a):
    sig = sign(a[0])
    prev = float('-inf')
    sol = 0
    for x in a:
        if sign(x) != sig:
            sol += prev
            prev = x
            sig = sign(x)
        else:
            prev = max(prev, x)
    return sol + prev

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(n, a))