def read():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def sign(n):
    return -1 if n < 0 else 1


def solve(n, a):
    total = 0
    m = a[0]
    s = sign(a[0])
    for i in range(1, n):
        si = sign(a[i])
        if si == s:
            m = max(a[i], m)
        else:
            total += m
            s = si
            m = a[i]

    total += m
    return total


for i in range(int(input())):
    result = solve(*read())
    print(result)
