def right_pl(past, current):
    return (past > 0 and current > 0) or (past < 0  and current < 0)


for item in range(int(input())):
    input()
    mass = list(map(int, input().split()))
    buff = []
    ans = []
    mass.append(0)
    for iter in range(1, len(mass)):
        if right_pl(mass[iter], mass[iter - 1]):
            buff += [mass[iter], mass[iter - 1]]
        else:
            buff.append(mass[iter - 1])
            ans.append(buff)
            buff = []
    print(sum([max(iter) for iter in ans]))
