t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    max_pos_so_far = (0, -float('inf'))
    max_neg_so_far = (0, -float('inf'))
    max_so_far = (0, -float('inf'))
    for i in range(n):
        if a[i] < 0:
            max_neg_ending_here = max((1, a[i]), (max_pos_so_far[0] + 1, max_pos_so_far[1] + a[i]))
            max_neg_so_far = max(max_neg_so_far, max_neg_ending_here)
        else:
            max_pos_ending_here = max((1, a[i]), (max_neg_so_far[0] + 1, max_neg_so_far[1] + a[i]))
            max_pos_so_far = max(max_pos_so_far, max_pos_ending_here)

        max_so_far = max(max_so_far, max_pos_so_far, max_neg_so_far)

    print(max_so_far[1])
