def solve():
    T = int(input())
    for t in range(T):
        n = int(input())
        nums = list(map(int, input().split()))
        s_idx = [0]
        for i in range(1, n):
            if nums[i-1] * nums[i] < 0:
                s_idx.append(i)
        s_idx.append(n)
        arr = []
        for i in range(1, len(s_idx)):
            arr.append(max(nums[s_idx[i-1]:s_idx[i]]))
        print(sum(arr))

solve()