for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    i = 0
    sm = 0
    while(i < n):
        if(a[i] < 0):
            mx = a[i]
            while(a[i] < 0):
                mx = max(mx,a[i])
                i += 1
                if(i >= n):
                    break
            sm += mx

        if(i < n):
            if(a[i] > 0):
                mx = a[i]
                while(a[i] > 0):
                    mx = max(mx,a[i])
                    i += 1
                    if(i >= n):
                        break
                sm += mx
        

        
                    
    print(sm)
        
        

    
