def is_same(x,y):
    if (x<0 and y<0) or (x>0 and y>0):
        return True 
    else:
        return False
        

t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().strip().split()))

    stack = []

    for i in range(n):
        if not stack:
            stack.append(arr[i])
        else:
            if is_same(stack[-1],arr[i]):
                if arr[i]>stack[-1]:
                    stack.pop()
                    stack.append(arr[i]) 
            else:
                stack.append(arr[i]) 
    print(sum(stack))


