def helper(l, i, n, v):
    t = [l[i]]
    if v > 0:
        while i < n-1 and l[i+1] > 0:
            t.append(l[i+1])
            i += 1
    else:
        while i < n-1 and l[i+1] < 0:
            t.append(l[i+1])
            i += 1
    return i, max(t)


def solve():
    n = int(input())
    l = list(map(int, input().split()))
    s = 0
    i = 0
    while i < n:
        if l[i] > 0:
            i, a = helper(l, i, n, 1)
        else:
            i, a = helper(l, i, n, -1)
        s += a
        i += 1
    return s


for __ in range(int(input())):
    print(solve())
