##Dictionary counter
#from collections import Counter 
# b=Counter(l)
#    ma=0
#    for j in b:
#        ma=max(ma,b[j])


##MAtrix Input
#matrix=[]
#    for k in range(9):
#        a=[]
#        a=list(map(str,input()))
#        ind=a.index('1')
#        a.remove('1')
#        a.insert(ind,'2')
#        matrix.append(a)


##Tree
#class Tree(object):
#    def __init__(self):
#        self.left = None
#        self.right = None
#        self.data = None
#
#root = Tree()
#root.data = "root"
#root.left = Tree()
#root.left.data = "left"
#root.right = Tree()
#root.right.data = "right"
#
#print(root.left.data)


N=int(input())
    
for i in range(N):
    n=int(input())
    s=list(map(int,input().split()))
#    a,b=map(int,input().split())
    a=[]
    t=0
    
    if(s[0]>0):
        t=s[0]
        for i in range(1,n):
            if(s[i]>0 and s[i-1]>0):
                t=max(t,s[i])
            if(s[i]<0 and s[i-1]>0):
                a.append(t)
                t=min(t,s[i])
            if(s[i]<0 and s[i-1]<0):
                t=max(t,s[i])
            if(s[i]>0 and s[i-1]<0):
                a.append(t)
                t=max(t,s[i])
            if(i==n - 1):
                if(len(a)>0):
                    if(a[len(a)-1]>0 and t > 0):
                        a[len(a)-1] = max(t, a[len(a)-1])
                    if(a[len(a)-1]<0 and t < 0):
                        a[len(a)-1] = max(t, a[len(a)-1])
                    else:
                        a.append(t)
                else:
                    a.append(t)
    if(s[0]<0):
        t=s[0]
        for i in range(1,n):
            if(s[i]>0 and s[i-1]>0):
                t=max(t,s[i])
            if(s[i]<0 and s[i-1]>0):
                a.append(t)
                t=min(t,s[i])
            if(s[i]<0 and s[i-1]<0):
                t=max(t,s[i])
            if(s[i]>0 and s[i-1]<0):
#                print(t)
                a.append(t)
#                print(t,s[i-1])
                t=max(t,s[i])
            if(i==n - 1):
                if(len(a)>0):
                    if(a[len(a)-1]>0 and t > 0):
                        a[len(a)-1] = max(t, a[len(a)-1])
                    if(a[len(a)-1]<0 and t < 0):
                        a[len(a)-1] = max(t, a[len(a)-1])
                    else:
                        a.append(t)
                else:
                    a.append(t)
#            print(a,i)
#    for i in range(1,len(a)):
#        if(a[i-1]>0 and a[i]>0):
#            print('err')
#        if(a[i-1]<0 and a[i]<0):
#            print('err')
    if n==1:
        print(s[0])
        continue
    print(sum(a))
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        