#include<bits/stdc++.h>
using namespace std;
struct node{
    int val;node* left;node*right;
};
node* f(int a[],int b,int e){
    if(b>e)return NULL;
    if(b==e){
        node* root=new node();
    root->val=a[b];root->left=NULL;root->right=NULL;return root;
    }
    int i,m,j;m=0;for(i=b;i<=e;i++){
        if(a[i]>m){m=a[i];j=i;}
    }
    node* root=new node();
    root->val=m;root->left=NULL;root->right=NULL;
    root->left=f(a,b,j-1);
    root->right=f(a,j+1,e);return root;
}
int main(){
    long long int i,j,n,t,x;cin>>t;
    while(t--){
      cin>>n;int a[n];
      for(i=0;i<n;i++)cin>>a[i];
      node* root=f(a,0,n-1);
      queue<pair<node*,int>>q;
      q.push(make_pair(root,0));map<int,int>m;
      while(!q.empty()){
          node* r=q.front().first;
          x=q.front().second;m[r->val]=x;q.pop();
          if(r->left)q.push(make_pair(r->left,x+1));
          if(r->right)q.push(make_pair(r->right,x+1));
      }
      for(i=0;i<n;i++){
          cout<<m[a[i]]<<" ";
      }
      cout<<endl;
    }
       
    }
