import sys

__author__ = 'ratmir'

[t] = [int(x) for x in sys.stdin.readline().split()]

for ti in range(0, t):
    [n] = [int(x1) for x1 in sys.stdin.readline().split()]
    x = [int(x1) for x1 in sys.stdin.readline().split()]
    # n = n + 1

    positive = x[0] > 0

    sm = 0
    cr = x[0]
    for i in range(1, n):
        if positive and x[i] > 0:
            if x[i] > cr:
                cr = x[i]
        if not positive and x[i] < 0:
            if x[i] > cr:
                cr = x[i]
        if positive and x[i] < 0:
            sm += cr
            positive = False
            cr = x[i]
        if not positive and x[i] > 0:
            sm += cr
            positive = True
            cr = x[i]
    sm += cr

    print sm
