test = int(input())
sol = []

def sqn(a:int):
    if a < 0:
        return False
    return True

while test:
    test -= 1
    n = int(input())
    a = [int(i) for i in input().split()]
    last = sqn(a[0])
    nr = a[0]
    sum = 0
    ok = False
    for i in range(n):
        if last == sqn(a[i]):
            if nr < a[i]:
                nr = a[i]
        else:
            sum += nr
            last = not last
            nr = a[i]
        if i == n - 1:
            sum += nr

    sol.append(sum)
for i in sol:
    print(i)