def solve(d):
    sol = []
    for a in d:
        if not sol:
            sol.append(a)
        else:
            last = sol[-1]
            if last > 0 and a > 0 and a > last:
                sol[-1] = a
            elif last > 0 and a < 0:
                sol.append(a)
            elif last < 0 and a < 0 and a > last:
                sol[-1] = a
            elif last < 0 and a > 0:
                sol.append(a)
    return sum(sol)


test_cases = int(input())
for i in range(test_cases):
    input()
    d = [int(a) for a in input().split(" ")]
    print(str(solve(d)))
