def task_1343_c():
    b = int(input())
    array = [int(num) for num in input().split()]

    maxPositive = 0
    minNegative = -10000000000
    res = 0

    for i in range(b):
        if array[i] < 0:
            if i != 0 and array[i - 1] >= 0:
                res += maxPositive
                maxPositive = 0
            minNegative = max(minNegative, array[i])
        else:
            if i != 0 and array[i - 1] < 0:
                res += minNegative
                minNegative = -10000000000
        maxPositive = max(maxPositive, array[i])
    
    if minNegative == -10000000000:
        res += maxPositive
    else:
        res += maxPositive + minNegative

    print(res)

a = int(input())
for i in range(a):
    task_1343_c()
