def solve(a):
    res = 0
    current = None
    for v in a:
        if current is None:
            current = v
        else:
            if (current > 0) == (v > 0):
                current = max(current, v)
            else:
                res += current
                current = v
    if current is not None:
        res += current
    return res


def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        print(solve(a))


if __name__ == '__main__':
    main()
