import sys


def sign(x):
    return 1 if x > 0 else -1


def single_solve(n, a):
    total = 0
    i = 0
    while i < n:
        current = a[i]
        j = i
        while j < n and sign(a[j]) == sign(a[i]):
            current = max(current, a[j])
            j += 1
        total += current
        i = j
    return f"{total}"


def solve(input_path=None):
    if input_path is None:
        f = sys.stdin
    else:
        f = open(input_path, 'r')

    golds = list()
    t = int(f.readline())
    for _ in range(t):
        n = int(f.readline())
        a = list(map(int, f.readline().split()))

        golds.append(single_solve(n, a))

    return golds


def main():
    for line in solve():
        print(f"{line}")


if __name__ == '__main__':
    main()
