t = int(input())
answer = []
nums = []
for i in range(t):
    line=input()
    line = input()
    ar = line.split(' ')
    stack = [int(ar[0])]
    for el in ar[1:]:
        el = int(el)
        if el>stack[-1]:
            if stack[-1]/abs(stack[-1]) == el/(abs(el)):
                stack[-1]=el
            else:
                stack.append(el)
        elif stack[-1]/abs(stack[-1]) != el/(abs(el)):
            stack.append(el)

        
    answer.append(sum(stack))


for a in answer:
    print(a)