n=int(input())
for i in range(n):
    k=int(input())
    l=[int(i) for i in input().split()]
    win=0
    k=[]
    m=[]
    for b in l:
        if win==0 and b<0:
            m.append(b)
            win=1 
        elif win==1 and b<0:
            m.append(b)
        elif win==1 and b>0:
            k.append(max(m))
            m=[]
            win=-1
            m.append(b)
        elif win==0 and b>0:
            m.append(b)
            win=-1 
        elif win==-1 and b>0:
            m.append(b)
        elif win==-1 and b<0:
            k.append(max(m))
            m=[]
            win=1
            m.append(b)
    k.append(max(m))
        
    print(k)        