def sign(n):
    return n > 0


for _ in range(int(input())):
    n = int(input())
    p = list(map(int, input().split()))
    sm = 0
    i = 0
    while i < n:
        cs = sign(p[i])
        j = i+1
        while j < n:
            if cs != sign(p[j]):
                break
            j += 1
        sm += max(p[i:j])
        i = j
    print(sm)
