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

for _ in range(int(input())):
    n = int(input())
    ans = 0
    prev = -10**9 - 1
    for x in [int(x) for x in input().split()]:
        if prev == -10**9 - 1 or sgn(x) == sgn(prev):
            prev = max(prev, x)
        else:
            ans += prev
            prev = x
    ans += prev
    print(ans)