def solution(t):
    for i in range(t):
        input()
        m1 = [int(x) for x in input().split()]
        last = count = 0
        sign = -1 if m1[0] > 0 else 1
        for v in m1:
            t = 1 if v > 0 else -1
            if t != sign:
                last = v
                sign = t
                count += v
            else:
                if v > last:
                    count -= last
                    last = v
                    count += v

        print(count)


def main():
    t = int(input())
    solution(t)


if __name__ == "__main__":
    main()
