T = int(input())
for _ in range(T):
    n = int(input())
    l = list(map(int,input().split()))
    bi = []
    for i in range(n):
        if l[i]<0:
            bi.append(0)
        else:
            bi.append(1)
    zero = []
    one = []
    for i in range(n):
        if bi[i]==0:
            zero.append(i)
            break
    for i in range(n):
        if bi[i]==1:
            one.append(i)
            break
    if len(zero)==0 or len(one)==0:
        print(max(l))
        continue
    negpre = l[0]
    su0 = negpre
    if negpre<0:
        flag0 = 1
    else:
        flag0 = 0
    for i in range(1,n):
        if bi[i]==0:
            if flag0==1:
                if l[i]>negpre:
                    su0-=negpre
                    su0+=l[i]
                    negpre = l[i]
            else:
                su0+=l[i]
                negpre = l[i]
                flag0 = 1
        elif bi[i]==1:
            if flag0==0:
                if l[i]>negpre:
                    su0-=negpre
                    su0+=l[i]
                    negpre = l[i]
            else:
                su0+=l[i]
                negpre = l[i]
                flag0 = 0
    
    print(su0)
        
                
                    
                    
            
            
    