from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict
import math
 
def listIn():
    return list((map(int,stdin.readline().strip().split())))
 
def stringListIn():
    return([x for x in stdin.readline().split()])
    
def intIn():
    return (int(stdin.readline()))
 
def stringIn():
    return (stdin.readline().strip())
    
    

if __name__=="__main__":
    t=intIn()
    for _ in range(t):
        n=intIn()
        arr=listIn()
        ans=0
        li=[]
        if n==1:
            print(arr[0])
        else:
            for i in range(n):
                if arr[i]<0:
                    li.append(0)
                else:
                    li.append(1)
                    
            m=arr[0]
            
            #print(li)
            for i in range(n):
                if i<n-1 and li[i]==li[i+1]:
                    m=max(m,arr[i],arr[i+1])
                elif i>0 and i<n-1 and (li[i]!=li[i-1] and li[i]!=li[i+1]):
                    ans+=arr[i]
                elif i==n-1:
                    if li[i]==li[i-1]:
                        #print(m)
                        ans+=m
                        m=float("-inf")
                    else:
                        ans+=arr[i]
                else:
                    ans+=m
                    m=float("-inf")
                    
                
            print(ans)
                    
                
                
            
                
    
        
    
    
    
    
    
    
    
    
    