t = int(input())

while(t):

    n = int(input())

    seq = list(map(int,input().split()))

    res2=[]
    for x in seq:

        if(x<0):
            if(len(res2)==0):
                res2.append(x)

            elif(res2[-1] > 0):
                res2.append(x)

            elif(res2[-1] < 0):
                if(res2[-1] < x ):
                    res2[-1] = x
            

        elif(x>0):
            if(len(res2)==0):
                res2.append(x)

            elif(res2[-1] < 0):
                res2.append(x)

            elif(res2[-1] > 0):
                if(res2[-1] < x ):
                    res2[-1] = x
            
            
    print(sum(res2))

    t-=1