# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 17:33:16 2020

@author: Katherine
"""

t = int(input())

for i in range(0, t):
    n = int(input())
    
    listb = input()
    
    listb = listb.split()
    
    listb = [int(x) for x in listb]
    
    lastElement = 0
    sumE = 0
    for i in listb:
        
        if lastElement == 0:
            
            lastElement = i
        
        elif i > 0:
            if lastElement < 0:
                
                sumE += lastElement
                
                lastElement = i
                
            elif lastElement < i:
                
                lastElement = i
                
            else:
                
                continue
                 
        else:
            
            if lastElement > 0:
                    
                sumE += lastElement
                    
                lastElement = i
                    
            elif lastElement < i:
                    
                lastElement = i
                    
            else:
                
                continue
            
    sumE += lastElement
            
    print(sumE)