import sys
# sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
# arr = [[int(el) for el in input().split()] for i in range(n)]


def solve(n, arr):

    pos = [0, 0, 0] #last, length, sum
    neg = [0, 0, 0]

    for i in arr:
        if i > 0:
            if i > pos[0]:
                pos[2] = pos[2] - pos[0] + i
                pos[0] = i

            if (neg[1] + 1 > pos[1]) or (neg[1] + 1 == pos[1] and neg[2] + i > pos[2]):
                pos = list(neg)
                pos[2] += i
                pos[0] = i
                pos[1] += 1

        elif i < 0:

            if i > neg[0]:
                neg[2] = neg[2] - neg[0] + i
                neg[0] = i

            if (pos[1] + 1 > neg[1]) or (pos[1] + 1 == neg[1] and pos[2] + i > neg[2]):
                neg = list(pos)
                neg[2] += i
                neg[0] = i
                neg[1] += 1

    if pos[1] > neg[1]:
        return pos[2]
    elif pos[1] < neg[1]:
        return neg[2]
    else:
        return max(pos[2], neg[2])


t = int( input() )

for _ in range(t):

    n = int(input())

    arr = list(map(int, input().split()))

    ans = solve(n, arr)

    print (ans)