num_cases = int(input())
for _ in range(num_cases):
    num = int(input())
    arr = [int(num) for num in input().split()]
    count = 0
    sum1 = 0
    sub_arr = []
    sign = arr[0] > 0 # true gives positive, else neg
    for elt in arr:
        test = elt > 0
        if test == sign:
            sub_arr.append(elt)
            count += 1
        else:
            sum1 += max(sub_arr)
            sub_arr = [elt]
            sign = not sign
    print(sum1 + max(sub_arr))