for _ in range(int(input())):
    n, = map(int, input().split())
    r = 0
    c = 0
    for v in map(int, input().split()):
        if c * v > 0:
            c = max(c, v)
        else:
            r += c
            c = v
    print(r + c)
