t = int(input())
for i in range(t):
    n=int(input())
    qq = list(map(int,input().split()))
    
    
    ss = []
    test = False
    nn=0
    mm=0
    if qq[0] < 0:
        test  = True
        nn=qq[0]
    else:
        mm = qq[0]
        
    for i in range(0,n):
        if test == False:
            if qq[i]>0:
                mm = max(mm,qq[i])
                continue
            else:
                ss.append(mm)
                nn = qq[i]
                test = True
        else:
            if qq[i]<0:
                nn = max(nn,qq[i])
                continue
            else:
                ss.append(nn)
                mm = qq[i]
                test = False
    if test == True:
        ss.append(nn)
    else:
        ss.append(mm)
    
    print(sum(ss))
    
        
                
                
        
        
    
        