t = int(input())

for z in range(t):
    n = int(input())
    data = input().split()
    array = []
    for i in data:
        array.append(int(i))
    j = 0
    total = 0
    while j < n:
        maximum = 0
        minimum = 0
        while (j < n and array[j] > 0):
            if maximum < array[j]:
                maximum = array[j]
            j += 1
        total += maximum

        while ( j < n and array[j] < 0):
            if minimum < array[j]:
                minimum = array[j]
            elif minimum == 0:
                minimum = array[j]
            j += 1
        total += minimum

    print(total)
