n = int(input())

for i in range(n):
    t = int(input())
    mas = list(map(int,input().split()))
    answer =  [ ]
    znak = True
    c = 1
    Sum = mas[0]
    Max = 0
    for i in range(t-1):
        if mas[i]*mas[i+1] < 0:
            c += 1
            answer.append(mas[i])
        else:
            mas[i+1] = max(mas[i],mas[i+1])
    answer.append(mas[-1])
    #print(*answer)
    print(sum(answer))