tests = int(input())
while tests > 0:
    tests -= 1
    n = int(input())
    arr = list(map(int, input().split()))
    maxAmt = [0]*2
    maxSum = [0]*2
    for i in range(n-1, -1, -1):
        nAmt = [0]*2
        nSum = [0]*2
        for j in range(0, 2):
            nAmt[j] = maxAmt[j]
            nSum[j] = maxSum[j]
        my = 0
        if arr[i] < 0:
            my = 1
        if 1+maxAmt[my^1] > nAmt[my]:
            nAmt[my] = 1+maxAmt[my^1]
            nSum[my] = arr[i]+maxSum[my^1]
        elif 1+maxAmt[my^1] == nAmt[my] and arr[i]+maxSum[my^1] > nSum[my]:
            nSum[my] = arr[i]+maxSum[my^1]
        maxAmt = nAmt
        maxSum = nSum
    ans = maxSum[0]
    if maxAmt[1] > maxAmt[0]:
        ans = maxSum[1]
    elif maxAmt[1] == maxAmt[0]:
        ans = max(ans, maxSum[1])
    print(ans)
            
        
