# -*- coding: utf-8 -*-
"""
Created on Sat Dec  7 22:36:40 2019

@author: Deepanshu
"""

t=int(input())

for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    suml=0
    curm=l[0]
    for i in range(n-1):
        if l[i]*l[i+1]<0:
            suml+=curm
            curm=l[i+1]
        else:
            curm=max(curm,l[i+1])
            
    #curm=max(curm,l[-1])
    suml+=curm
    print(suml)
    
        
    
    