t =int(input())

for tt in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    stack = []
    stack.append(l[0])
    top=1
    for i in range(1,n):
        if stack[top-1]>0 and l[i]>0:
            if stack[top-1]<l[i]:
                stack[top-1]=l[i]
        elif stack[top-1]>0 and l[i]<0:
            stack.append(l[i])
            top+=1
        elif stack[top-1]<0 and l[i]<0:
            if stack[top-1]<l[i]:
                stack[top-1]=l[i]
        elif stack[top-1]<0 and l[i]>0:
            stack.append(l[i])
            top+=1
    print(sum(stack))
