import sys

def solve(turn):
    list_b = [-1 if turn else 1]
    for i in range(n):
        num = list_num[i]
        if num * list_b[-1] < 0:
            list_b.append(num)
        elif num > list_b[-1]:
            list_b[-1] = num
    return (len(list_b)-1, sum(list_b) + (1 if turn else -1))

        

t=int(sys.stdin.readline())
for _ in range(t):
    n = int(sys.stdin.readline())
    list_num = list(map(int, sys.stdin.readline().split()))
    print(max(solve(0), solve(1))[1])