def solve():
    sum = 0
    part_max = - 10**9
    pos = a[0]>0
    for ai in a:
        if (ai>0) == pos:
            part_max = max(part_max, ai)
        else:
            sum+= part_max
            part_max = ai
            pos = not pos
    sum += part_max
    print(sum)
    return






t = int(input())  # read a line with a single integer
for i in range(1, t + 1):
    n = int(input())
    a = [int(s) for s in input().split(" ")]  # read a list of integers, 2 in this case
    solve()
