for _ in range(int(input())):
    Ans = []
    N = int(input())
    X = list(map(int, input().split()))
    i, Current = 0, X[0]
    while i < N:
        if X[i] > 0 and Current > 0:
            Current = max(Current, X[i])
        elif X[i] < 0 and Current < 0:
            Current = max(Current, X[i])
        else:
            Ans.append(Current)
            Current = X[i]
        i += 1
    print(sum(Ans)+Current)

# I want to take my rank back again
# Hope the best for Ravens member
