from sys import stdin


def inp():
    return stdin.buffer.readline().rstrip().decode("utf8")


def itg():
    return int(stdin.buffer.readline())


def mpint():
    return map(int, stdin.buffer.readline().split())


for case in range(itg()):
    n = itg()
    arr = list(mpint())
    max_ = arr.pop(0)
    last_sign = max_ > 0  # True: +
    ans = 0
    for a in arr:
        if last_sign:
            if a > 0:  # + +
                max_ = max(max_, a)
            else:  # + -
                ans += max_
                max_ = a
                last_sign = False
        else:
            if a > 0:  # - +
                ans += max_
                max_ = a
                last_sign = True
            else:  # --
                max_ = max(max_, a)
    ans += max_  # last one
    print(ans)
