t = int(input())

for i in range(t):
    n = int(input())
    summ = 0
    final = -10 ** 10
    prev = 0
    for elem in map(int, input().split()):
        if (prev > 0 and elem < 0) or (prev < 0 and elem > 0):
            summ += final
            prev = 0
            final = -10 ** 10
        if elem > final:
            final = elem
        prev = elem
    print(summ + final)
