t = int(input()) 
for _ in range (t): 

    n = int(input()) 
    L = list(map(int, input().split())) 
    answer = [0]*n 
    length = [0]*n 

    maxNeg = None 
    maxPos = None 
    negLen = 0 
    posLen = 0 

    for i in range (n): 

        if L[i]>0:

            if maxNeg is None: 
                answer[i] = L[i] 
            else: 
                answer[i] = maxNeg + L[i] 

            length[i] = negLen + 1
            if length[i] > posLen: 
                maxPos = answer[i] 
            else: 
                maxPos = max (maxPos, answer[i])  
            posLen = max (posLen, length[i]) 


        else:

            if maxPos is None: 
                answer[i] = L[i] 
            else: 
                answer[i] = maxPos + L[i] 

            length[i] = posLen + 1
            if length[i] > negLen:
                maxNeg = answer[i] 
            else: 
                maxNeg = max (maxNeg, answer[i]) 
            negLen = max (negLen, length[i]) 
    
    maxLen = max(length) 
    m = min (answer) 
    for i in range (n): 
        if length[i] == maxLen: 
            m = max(m, answer[i]) 
    
    print(m) 