import sys

t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))

    round1sum = 0

    i = 0
    while i < n:
        if arr[i] > 0:
            maxsofar = 0
            while i < n and arr[i] > 0:
                maxsofar = max(arr[i], maxsofar)
                i += 1
            round1sum += maxsofar
        else:
            maxsofar = -sys.maxsize
            while i < n and arr[i] < 0:
                maxsofar = max(maxsofar, arr[i])
                i += 1
            round1sum += maxsofar

    print(round1sum)