def calculateMaxSum(n, li):
    array = []
    array.append(li[0])

    large = []

    for j in range(0, n - 1):

        if li[j] > 0 and li[j + 1] > 0:
            array.append(li[j + 1])
        elif li[j] > 0 and li[j + 1] < 0:
            large.append(max(array))
            array = []
            array.append(li[j + 1])
        elif li[j] < 0 and li[j + 1] > 0:
            large.append(max(array))
            array = []
            array.append(li[j + 1])
        else:
            array.append(li[j + 1])

    large.append(max(array))

    return sum(large)


t = int(input())
while t != 0:
    size = int(input())
    arr = [int(x) for x in input().split()]
    print(calculateMaxSum(size, arr))
    t -= 1


# Driver code
# list = [-2, 8, 3, 8, -4, -15, 5, -2, -3, 1]
# N = len(list)

# print(calculateMaxSum(N, list))
