for i in range(int(input())):
    length = int(input())
    array = list(map(int, input().split()))
    CURRENT = 0
    SUMM = 0
    current_array = []
    for j in range(length):
        if j == 0:
            if int(array[j] > 0):
                CURRENT = 1
            current_array.append(array[j])
        elif j == length - 1:
            if int(array[j] > 0) != CURRENT:
                SUMM += max(current_array)
                SUMM += array[j]
            else:
                current_array.append(array[j])
                SUMM += max(current_array)
        else:
            if int(array[j] > 0) == CURRENT:
                current_array.append(array[j])
            else:
                SUMM += max(current_array)
                current_array = [array[j]]
                CURRENT = int(array[j] > 0)
    print(SUMM)