def solve():
    n = int(input())
    A = list(map(int, input().split()))
    A.append(-A[-1])
    if n == 1:
        print (A[0])
        return

    if A[0] > 0:
        lp = True
        pos = A[0]
        neg = -10**10
    else:
        lp = False
        neg = A[0]
        pos = 0

    answer = 0
    for a in A[1:]:
        if a > 0:
            if lp:
                pos = max(pos, a)
            else:
                lp = True
                answer += neg
                pos = a
        else:
            if not lp:
                neg = max(neg, a)
            else:
                lp = False
                answer += pos
                neg = a
    print (answer)



t = int(input())
for i in range(t):
    solve()
