for i in range(int(input())):
    number = int(input())
    elements = list(map(int, input().split()))
    total = elements[0]
    item = elements[0]
    for j in range(1, number):
        if elements[j] < 0 < item:
            total += elements[j]
            item = elements[j]
        elif item > 0 and elements[j] > 0:
            if elements[j] > item:
                total -= item
                total += elements[j]
                item = elements[j]
        elif item < 0 < elements[j]:
            total += elements[j]
            item = elements[j]
        else:
            if elements[j] > item:
                total -= item
                total += elements[j]
                item = elements[j]
    print(total)


