m=[]
for i in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    a=l[0]
    k=0
    
    for j in range(len(l)):
        if (l[j]*a<0):
            k+=a
            a=l[j]
        else:
            
            
            a=max(l[j],a)
            
            
            
    print(k+a)