for _ in range(int(input())):
    
    n = int(input())
    l = list(map(int, input().split()))
    
    ans = l[0]
    current = l[0]
    for i in range(1,n):
        if(current > 0):
            if(l[i] > current):
                ans -= current
                current = l[i]
                ans += current
            elif(l[i] < 0):
                current = l[i]
                ans += current
        else:
            if(l[i]<0 and l[i]>current):
                ans -= current
                current = l[i]
                ans += current
            elif(l[i] > 0):
                current = l[i]
                ans += current
    print(ans)




        


    
    
    
    
    
    