def signlist(a,n):
    signs=[]
    k=[a[0]]
    for i in range(1,n):
        if a[i]*a[i-1]>0:
            k.append(a[i])
        else:
            signs.append(k)
            k=[a[i]]
    if a[n-1]*a[n-1]>0:
        signs.append(k)
    return(signs)    
            
            




def final(signs):
    final=[]
    for i in signs:
        try:
          final.append(max(i))
        except:
          final.append(i)  
    return(final)                 
            



t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    print(sum(final(signlist(a,n))))                 
    
