#include #include using namespace std; int arr[100010],ans[100010],f[100010],len; int binary_search(int i){ int left,right,mid; left=0,right=len; while(left=arr[i]) right=mid; else left=mid+1; } return left; } int main(){ // freopen("input","r",stdin); // freopen("output","w",stdout); int t; cin>>t; while(t--){ int n; cin>>n; for(int i=1; i<=n; i++) scanf("%d",&arr[i]); ans[1] = arr[1]; len=1; f[1]=1; for(int i=2; i<=n; ++i){ if(arr[i]>ans[len]){ ans[++len]=arr[i]; f[i]=len; } else{ int pos=binary_search(i); ans[pos] = arr[i]; f[i]=pos; } } for(int i=1;i