for t in range(int(input())):
    n=int(input())
    s = list(map(int,input().split()))
    
    maxNum =s[0];
    maxSum =0;
    p=True if s[0]>0 else False 
    for i in range(1,n):
        
        if(s[i]<0 and p==True):
            maxSum+=maxNum
            p=not p
            maxNum=s[i]
            
        elif(s[i]>0  and p ==False):
            maxSum+=maxNum
            p=not p
            maxNum=s[i]
        
        else:
            if(s[i]>maxNum):
                maxNum=s[i]
    
    print(maxSum+maxNum)