for tt in range(int(input())):
    q=int(input())
    n=[int(i) for i in input().split()]
    sm,l,fl,i,flag=n[0],-999999999999,n[0],1,True
    while(i<q):
        if((n[i]<0 and fl>0) or (n[i]>0 and fl<0)):
            sm+=n[i]
            #print(sm,fl,n[i])
            fl=n[i]
            flag=False
            
        else:
            
            if(l<sm):
                l=sm
            fl,sm=n[i],n[i]
            #print(fl)
        i+=1      
    if(flag==True):
        l=max(n)
    if(l==-999999999999):
        print(sm)
    else:
        print(l)