def solution():
    n = int(input())
    for _ in range(n):
        m = int(input())
        nums = list(map(int, input().split()))
        current_max = nums[0]
        i = 1
        negative = False
        if current_max < 0:
            negative = True
        result_sum = 0
        while i < m:
            if negative:
                if nums[i] > 0:
                    result_sum += current_max
                    current_max = nums[i]
                    negative = False
                elif nums[i] > current_max:
                    current_max = nums[i]
            else:
                if nums[i] < 0:
                    result_sum += current_max
                    current_max = nums[i]
                    negative = True
                elif nums[i] > current_max:
                    current_max = nums[i]
            i += 1
        result_sum += current_max
        print(result_sum)


solution()
