for test in range(int(input())):
    n = int(input())
    a = [*map(int, input().split())] + [0]
    answer = 0
    counter = 0
    element = None
    old = None
    for element in a:
        if element == 0:
            answer += old
        if old == None:
            old = element
        elif old * element < 0:
            answer += old
            old = element
        else:
            old = max(old, element)
    print(answer)