t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))

    IND=[]
    for j in range(1,len(l)):
        if abs(l[j]+l[j-1])<abs(l[j])+abs(l[j-1]):
            IND.append(j)

    if len(IND)==0:
        print(max(l))
        continue
    BABA=[]
    BABA.append(l[:IND[0]])

    for j in range(1,len(IND)):
        BABA.append( l[IND[j-1]:IND[j]] )

    BABA.append( l[IND[-1]:] )

    JAX=[]
    for j in range(len(BABA)):
        JAX.append(max(BABA[j]))
    print(sum(JAX))
        
    