import sys

t = int(sys.stdin.readline())
for _ in xrange(t):
    n = int(sys.stdin.readline())
    arr = map(int, sys.stdin.readline().split())

    was_pos = arr[0] > 0

    res = 0
    cur_max = None
    for i, x in enumerate(arr):
        if x < 0 and was_pos:
            res += cur_max
            was_pos = False
            cur_max = None
        elif x > 0 and not was_pos:
            res += cur_max
            was_pos = True
            cur_max = None

        if cur_max is None:
            cur_max = x
        else:
            cur_max = max(cur_max, x)
    if cur_max is not None:
        res += cur_max
    sys.stdout.write(str(res) + '\n')

