n = int(input())

ans = []

for i in range(n):
    
    m = int(input())
    l = list(map(int,input().split()))
    sum = 0
    k = 0
    
    while k<m:
        s = l[k]
        k+=1
        while k<m and l[k]*l[k-1]>0:
            s = max(s,l[k])
            k += 1
        sum += s
    
    ans.append(sum)

for i in ans:
    print(i)
        
    
