if __name__ == "__main__":
   
    t = int(input())
    anslist=[]
   
    for i in range(t):
   
        n = int(input())
        li = list(map(int,input().split()))
        
               
    
        key = li[0]
        total = li[0]
    
        for i in range(1,n):
        
            if (li[i]>0 and li[i-1] >0) or (li[i]<0 and li[i-1] < 0):
                if li[i] > key:
                    total = total + li[i] - key
                    key = li[i]
        
            else:
                total = total + li[i]
                key = li[i]
        anslist.append(total)
    
    for i in anslist:
        print(i)            
        