
t = int(input())
for i in range(t):
    a = int(input())
    maxi = 0
    sign = 0
    tot = 0
    x = input().split()
    for j in range(a):
        y = int(x[j])
        if sign*y == 0:
            maxi = y
            if y < 0:
                sign = -1
            else:
                sign = 1
        elif sign*y > 0:
            if y > maxi:
                maxi = y
        else:
            print(f"Current maxi {maxi}")
            tot += maxi
            maxi = y
            print(f"Next maxi {maxi}")
            sign *= -1
    print(tot)