import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

tokens = []
tokens_next = 0


def next_str():
    global tokens, tokens_next
    while tokens_next >= len(tokens):
        tokens = input().split()
        tokens_next = 0
    tokens_next += 1
    return tokens[tokens_next - 1]


def nextInt():
    return int(next_str())


def f(a, st):
    # stNextSeg = next(i for i in range(st, len(a)) if a[i] * a[st] < 0)

    myMax = a[st]
    j = st
    for j in range(st, len(a)):
        if a[j] * a[st] < 0:  # opp. sign
            return (myMax, j)
        myMax = max(myMax, a[j])

    return (myMax, len(a))


t = nextInt()
for _ in range(t):
    n = nextInt()
    a = [nextInt() for _ in range(n)]

    sum = 0
    i = 0
    while i < len(a):
        curSegmentMax, nextInd = f(a, i)
        sum += curSegmentMax
        i = nextInd

    print(sum)
