
import collections


def solve(n, arr):
    positives = []
    negatives = []

    lastEncountered = None

    for i, num in enumerate(arr):
        if num > 0:
            if not lastEncountered or lastEncountered == -1:
                positives.append([num])
            else:
                positives[-1].append(num)

            lastEncountered = 1
        else:
            if not lastEncountered or lastEncountered == 1:
                negatives.append([num])
            else:
                negatives[-1].append(num)

            lastEncountered = -1

    # print("Positives: {}".format(positives))
    # print("Negatives: {}".format(negatives))

    consideringPos = False

    if arr[0] > 0:
        consideringPos = True

    i, j = 0, 0

    lenPos = len(positives)
    lenNeg = len(negatives)

    maxAnsPossible = 0

    while True:
        if consideringPos:
            if i >= lenPos:
                break

            maxAnsPossible += max(positives[i])
            i += 1
        else:
            if j >= lenNeg:
                break

            maxAnsPossible += max(negatives[j])
            j += 1

        consideringPos = not consideringPos

    return maxAnsPossible


t = int(input().strip())
# [n,m] = list(map(int, input().strip().split()))

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

    print(solve(n, arr))
