q = int(input())

for _ in range(q):
    n = int(input())
    ans = 0
    s = [int(i) for i in input().split()]
    t = s[0]
    m = t
    f = t>0
    for i in range(1, n):
        t = s[i]
        if t>0 and f or t<0 and not f:
            m = max(m, t)
        else:
            f = not f
            ans += m
            m = t
    ans += m
    print(ans)
