import os


def a(x, y):
    return x[0] + y[0], x[1] + y[1]


def f(nums):
    n = len(nums)
    dp_plus = [(0, 0)] * (n + 1)
    dp_minus = [(0, 0)] * (n + 1)
    for idx, x in enumerate(nums):
        ii = idx + 1
        if x > 0:
            p, m = dp_plus, dp_minus
        else:
            p, m = dp_minus, dp_plus

        p[ii] = max(a(m[ii - 1], (1, x)), p[ii - 1])
        m[ii] = m[ii - 1]

    return max(dp_plus[-1], dp_minus[-1])[1]


def pp(input):
    n_test = int(input())
    for i in range(n_test):
        input()
        print(f(list(map(int, input().split()))))


if "paalto" in os.getcwd():
    from string_source import string_source

    s = string_source(
        """4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000"""
    )

    pp(s)
else:
    pp(input)
