f = lambda x: 1 if x > 0 else -1
for _ in range(int(input())):
    n = int(input())
    s = list(map(int, input().split()))
    cur = f(s[0])
    max_ = -(10 ** 10)
    ans = 0
    for i in range(n):
        if cur == 0:
            cur = f(s[i])
        if cur * s[i] > 0:
            max_ = max(s[i], max_)
        else:
            ans += max_
            cur = f(s[i])
            max_ = s[i]
    ans += max_
    print(ans)
