for _ in range(int(input())):
    n = int(input())
    nums = list(map(int, input().split()))
    left = 0
    right = 0
    bestSeq = 0
    while (left < n):
        sign = 1
        if (nums[left] < 0):
            sign = 0
        if sign:
            right = left
            bestValue = 0
            while (right < n and nums[right] > 0):
                bestValue = max(nums[right], bestValue)
                right += 1
            bestSeq += bestValue
        else:
            right = left 
            bestValue = float("-inf")
            while (right < n and nums[right] < 0):
                bestValue = max(nums[right], bestValue)
                right += 1
            bestSeq += bestValue
        left = right
    print(bestSeq)