
import sys

stream = sys.stdin
# stream = open('input.txt', 'r')
t = int(stream.readline())

for n in stream:
    n = int(n)
    
    maxi = -float('inf')
    sums = 0   
    prev_num = 0
    
    for num in stream.readline().split():
        num = int(num)
        
        if prev_num * num < 0:
            sums += maxi
            maxi = -float('inf')
            
        if maxi < num:
            maxi = num
            
        prev_num = num
            
    sums += maxi
    print(sums)          
        
        