for i in range(int(input())):
    n = int(input())
    a = [int(i) for i in input().split()] 
    
    if a[0] > 0:
        ch = 1
        ma = a[0]
    else:
        ch = -1
        mi = a[0]
    sy = 0
    
        
    for j in range(1,n):
        if a[j] > 0:
            if ch == 1:
                ma = max(a[j],ma)
            else:
                sy += mi
                
                ch = 1
                ma = a[j]
                    
        else:
            if ch == -1:
                mi = max(a[j],mi)
            else:
                sy += ma
                
                ch = -1
                mi = a[j] 
    if a[-1] > 0:
        
        print(sy + ma)
    else:
        print(sy + mi)