import io
import os

from collections import Counter, defaultdict, deque


def solve(N, A):
    bestPos = (0, float("-inf"))
    bestNeg = (0, float("-inf"))
    for x in A:
        if x < 0:
            bestNeg = max(bestNeg, (bestPos[0] + 1, bestPos[1] + x))
            bestNeg = max(bestNeg, (1, x))
        else:
            assert x > 0
            bestPos = max(bestPos, (bestNeg[0] + 1, bestNeg[1] + x))
            bestPos = max(bestPos, (1, x))
    return max(bestPos, bestNeg)[1]


if __name__ == "__main__":
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    T = int(input())
    for t in range(T):
        (N,) = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]

        ans = solve(N, A)
        print(ans)
