t =int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    largest_in_group = l[0]
    sign_of_group = l[0]
    total_so_far = 0
    for num in l:
        if num * sign_of_group > 0: # matching sign
            largest_in_group = max(largest_in_group, num)
        else:
            total_so_far += largest_in_group
            largest_in_group = num
            sign_of_group = num
    total_so_far += largest_in_group
    print(total_so_far)
    # if sign was a boolean called is_positive -> num > 0 == is_positive

#Teacher's solution
