#include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define lb long double #define mod 1000000007 #define inf 9000000000000000000LL using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T,n; int a[100005],b[100005]; int ans[100005]; int main() { T=read(); while(T--) { memset(ans,127,sizeof(ans)); ans[0]=0; n=read(); for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++) { int t=lower_bound(ans,ans+n+1,a[i])-ans-1; b[i]=t+1; ans[t+1]=min(ans[t+1],a[i]); } for(int i=1;i<=n;i++) if(i!=n)printf("%d ",b[i]); else printf("%d",b[i]); puts(""); } return 0; }