
def same_sgn(x, y):
    if x > 0:
        return y > 0
    else:
        return y < 0


T = int(input())
for _ in range(T):
    n = int(input())
    nums = list(map(int, input().split()))
    s = [nums[0]]
    for i in range(n):
        if same_sgn(s[-1], nums[i]):
            if nums[i] > s[-1]:
                s[-1] = nums[i]
        else:
            s.append(nums[i])
    print(sum(s))
    




