t = int(input())
for _ in range(t):
    n = map(int, input())
    nums = map(int, input().split())
    maxLenNeg = 0
    maxLenPos = 0
    maxSumPos = 0
    maxSumNeg = 0

    for x in nums:
        if x < 0:
            if maxLenPos + 1 > maxLenNeg:
                maxLenNeg = maxLenPos + 1
                maxSumNeg = maxSumPos + x
            else:
                maxSumNeg = max(maxSumNeg, maxSumPos + x)
        else:
            if maxLenNeg + 1 > maxLenPos:
                maxLenPos = maxLenNeg + 1
                maxSumPos = maxSumNeg + x
            else:
                maxSumPos = max(maxSumPos, maxSumNeg + x)
    m = -1e18
    if maxLenPos >= maxLenNeg:
        m = max(m, maxSumPos)
    if maxLenNeg >= maxLenPos:
        m = max(m, maxSumNeg)
    print(m)
