from sys import stdin,stdout
def main():
    for _ in range(int(stdin.readline())):
        n=int(input())
        arr=[int(k) for k in input().split()]
        pos=0
        neg=0
        counter=0
        result=0
        for i in range(n):
            if arr[i]>0 and counter==0:
                pos=arr[i]
                counter=1
                result+=neg
                neg=0
            elif arr[i]>0 and counter==1:
                pos=max(pos,arr[i])
            elif arr[i]<0 and counter==1:
                result+=pos
                pos=0
                counter=0
                neg=arr[i]
            else:
                if i==0:
                    neg=arr[i]
                else:
                    neg=max(neg,arr[i])
        print(result+pos+neg)
                    
        
                
                
            
            
        
            
            
if __name__=="__main__":
    main()