t=int(input())
for i in range(t):
    n=int(input())
    num1=list(map(int,input().split()))
    num2=[num1[0]]
    a=max(num1)
    c=min(num1)
    b=0
    if a<0:
        print(a)
        b+=1
    if c>0:
        print(a)
        b+=1
    for i in range(1,n):
        if num1[i]<0 and num2[-1]>0:
            num2.append(num1[i])
        if num1[i]>0 and num2[-1]<0:
            num2.append(num1[i])
        if num2[-1]>0 and num1[i]>0 and num1[i]>num2[-1]:
            num2.pop()
            num2.append(num1[i])
        if num2[-1]<0 and num1[i]<0 and num1[i]>num2[-1]:
            num2.pop()
            num2.append(num1[i])
        else:
            continue
    if b==0:
        print(sum(num2))
        
    
        
        
        