#include #include #include #include #include #define M 100005 using namespace std; int rd(){ int res=0,k=1; char c; while (c=getchar(),!isdigit(c)&&c!='-'); if (c=='-') {k=-1; c=getchar();} do{ res=(res<<3)+(res<<1)+(c^48); }while (c=getchar(),isdigit(c)); return res*k; } int T,n,A[M],B[M],tree[M<<2],dp[M]; void Build(int L,int R,int p){ tree[p]=0; if(L==R)return; int mid=L+R>>1; Build(L,mid,p<<1); Build(mid+1,R,p<<1|1); } void Update(int L,int R,int x,int y,int p){ if(L==R){ tree[p]=max(tree[p],y); return; } int mid=L+R>>1; if(x<=mid)Update(L,mid,x,y,p<<1); else Update(mid+1,R,x,y,p<<1|1); tree[p]=max(tree[p<<1],tree[p<<1|1]); } int Query(int L,int R,int l,int r,int p){ if(L==l&&R==r)return tree[p]; int mid=L+R>>1; if(r<=mid)return Query(L,mid,l,r,p<<1); else if(l>mid)return Query(mid+1,R,l,r,p<<1|1); else return max(Query(L,mid,l,mid,p<<1),Query(mid+1,R,mid+1,r,p<<1|1)); } int main(){ T=rd(); while(T--){ n=rd(); for(int i=1;i<=n;++i){ A[i]=rd(); B[i]=A[i]; } sort(B+1,B+n+1); int len=unique(B+1,B+n+1)-B-1; for(int i=1;i<=n;++i) A[i]=lower_bound(B+1,B+len+1,A[i])-B; Build(1,n,1); for(int i=1;i<=n;++i){ if(A[i]==1)dp[i]=1; else{ int k=Query(1,n,1,A[i]-1,1); dp[i]=k+1; } Update(1,n,A[i],dp[i],1); printf("%d",dp[i]); if(i!=n)printf(" "); } puts(""); } return 0; }