def solution(sub):
    arr = []
    for i in range(len(sub)):
        if sub[i]>0:
            if not arr or arr[-1]<0: arr.append(sub[i]) 
            elif arr[-1] < sub[i]:
                arr.pop()
                arr.append(sub[i])
        elif sub[i]<0: 
            if not arr or arr[-1]>0: 
                arr.append(sub[i])
            elif arr[-1]<sub[i]: 
                arr.pop()
                arr.append(sub[i]) 
    return sum(arr)
 
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    print(solution(a))
                
