#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 20:52:26 2020

@author: dishabansal
"""

t=int(input())
for _ in range(t):
    n=int(input())
    l1=input().split(' ')
    l=[]
    for i in range(n):
        l+=[int(l1[i])]
    #print('l=',l)
    
    temp=[]
    i=0
    while i<n:
        if l[i]>0:
            cm=l[i]
            while l[i]>0:
                cm=max(cm,l[i])
                i+=1
                if i==n:
                    temp+=[cm]
                    break
            temp+=[cm]
        else:
            cm=l[i]
            while l[i]<0:
                cm=max(cm,l[i])
                i+=1
                if i==n:
                    temp+=[cm]
                    break
            temp+=[cm]
    #print('temp=',temp)
    l=temp[0:len(temp)-1]
    #print('l=',l) 
    dp=[]
    if l[0]>0:
        dp+=[[1,l[0]]]
    else:
        dp+=[[1,l[0]]]
    last=[]
    lp=-1
    ln=-1
    for i in range(len(l)):
        if l[i]>0:
            if ln==-1:
                last+=[-1]
            else:
                last+=[ln]
            lp=i
        else:
            if lp==-1:
                last+=[-1]
            else:
                last+=[lp]
            ln=i
    for i in range(1,len(l)):
        if l[i]>0:
            j = last[i]
            if j!=-1:
                dp+=[[dp[j][0]+1,dp[j][1]+l[i]]]
            else:
                dp+=[[1,l[i]]]
        else:
            j = last[i]
            if j!=-1:
                dp+=[[dp[j][0]+1,dp[j][1]+l[i]]]
            else:
                dp+=[[1,l[i]]]
    #print('dp=',dp)
    max_k=dp[-1][0]
    max_sum=dp[-1][1]
    for i in range(len(dp)-2,-1,-1):
        if dp[i][0]==max_k:
            max_sum=max(max_sum,dp[i][1])
    print(max_sum)