import sys
input=sys.stdin.readline
m=1000000007
def power(x,y): 
    res = 1
    while (y > 0):  
        if ((y & 1) == 1) : 
            res = (res * x )%m
        y = y >> 1
        x =( x * x )%m
      
    return res%m
##dp=[0]*30
##dp[0]=1
##for i in range(1,30):
##    dp[i]=dp[i-1]+power(2,i)

'''
5
2
4
6
8
10

'''

def main():
    for _ in range(int(input())):
        n=int(input())
        l=list(map(int,input().split()))
        c=-(1000000001)
        l1=[]
        l2=[]
        m2=0
        m1=c
        f=0
        for i in range(n):
            if(l[i]<0):
##                print(l[i],m1)
                if(l[i]>=m1):
                    m1=l[i]
                if(m2!=0):
                    l2.append(m2)
                m2=0
                f=1
            else:
                if(l[i]>m2):
                    m2=l[i]
                if(m1!=c):
                    l1.append(m1)
                m1=c
                f=2
        if(f==2):
            l2.append(m2)
        if(f==1):
            l1.append(m1)
        print(sum(l1)+sum(l2))
##        a,b=map(int,input().split())






















if __name__== "__main__":
  main()
