T = int(input())

for t in range(T):
    N = int(input())
    L = [int(i) for i in input().split()]

    is_positive = True
    current_v = 0
    answer = 0
    for i in range(len(L)):
        if is_positive:
            if L[i] > 0:
                current_v = max(current_v, L[i])
            else:
                is_positive = False
                answer += current_v
                current_v = L[i]
        else:
            if L[i] < 0:
                current_v = max(current_v, L[i])
            else:
                is_positive = True
                answer += current_v
                current_v = L[i]
    answer += current_v
    print(answer)
