def solve(n, elems):
    stk = [elems[0]]
    for i in range(1, n):
        if (stk[-1] < 0 and elems[i] > 0) or (stk[-1] > 0 and elems[i] < 0):
            stk.append(elems[i])
        else:
            stk[-1] = max(stk[-1], elems[i])
    print(sum(stk))


for _ in range(int(input())):
    solve(int(input()), list(map(int, input().strip().split())))