# -*- coding: utf-8 -*-
"""
Created on Thu Apr 15 19:36:22 2021

@author: Yogesh Panjwani
"""
t=int(input())
for k in range(t):
    n=int(input())
    
    a=list(map(int,input().split()))
    
    i=0
    
    s=0
    while(i<n-1):
        c=a[i]
    
        while(i<n-1 and a[i]*a[i+1]>0):
            m=max(a[i],a[i+1])
            c=max(c,m)
            i+=1
    
        s+=c 
        i+=1
    
    print(s)

    